类在作曲家的 PHP 中找不到异常 [英] Class not found exception in PHP from composer

查看:37
本文介绍了类在作曲家的 PHP 中找不到异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试包含来自 composer 的包,但我收到 class not found 错误.

I am trying to include a package from composer, but I am receiving a class not found error.

我已经尝试了以下可能性.

I have tried the below possibilities.

$supermeteor = new SupermeteorSupermeteor('XXXXXXXX');

use SupermeteorSupermeteor;
$supermeteor = new Supermeteor('xxxxxxxx');

包composer.json:

Packages composer.json:

"psr-4": {
     "Supermeteor\": ""
}

包命名空间:

namespace Supermeteor;

包类名:

class Supermeteor() {}

错误信息

未捕获的错误:在中找不到类SupermeteorSupermeteor"C:path omyfile.php:16

Uncaught Error: Class 'SupermeteorSupermeteor' not found in C:path omyfile.php:16

推荐答案

我刚刚在本地测试了您的包,使用与您在问题中提供的相同代码似乎对我来说工作正常.我就是这样测试的.

I just tested your package locally, and it seems to work fine for me using the same code as you provided in your question. This is how I tested it.

在您的计算机上创建一个新目录.

Create a new directory on your computer.

在命令行上找到您的新目录,并通过运行以下 composer 命令将包添加到您的项目自动加载器中.

Locate your new directory on the command line and add the package to your projects autoloader by running the below composer command.

composer require supermeteor/sdk-php

3.使用包

在您的 composer.json 所在目录下创建一个 index.php 文件并添加以下代码.

3. Use the package

Create an index.php file in the same directory as your composer.json and add the below code.

<?php
require_once __DIR__ . '/vendor/autoload.php';

use SupermeteorSupermeteor;

$supermeteor = new Supermeteor("xxx");

4.测试结果

在终端窗口中启动一个新的 php 服务器来为您的项目提供服务.

4. Test the results

In the terminal window start a new php server to serve your project.

php -S localhost:8089

现在通过浏览器访问该站点 http://localhost:8089.

Now access the site via your browser at http://localhost:8089.

这篇关于类在作曲家的 PHP 中找不到异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆