【发布时间】:2016-09-19 00:47:02
【问题描述】:
我正在使用我通过 Composer 下载的名为 Pheanstalk 的库。我正在运行以下脚本:
<?php
//... some unrelated code
require_once('vendor/autoload.php'); //loading the autoload file from composer
use Pheanstalk\Pheanstalk; //using the namespace
$pheanstalk = new Pheanstalk('127.0.0.1'); //initiating an object
//... some unrelated code
?>
出现如下错误:
Fatal Error: Class 'Pheanstalk\Pheanstalk' not found in /opt/lampp/htdocs/project_zero/index.php on line 16
第 16 行是:$pheanstalk = new Pheanstalk('127.0.0.1');
问题:为什么我会收到此错误?上面的脚本基本上是从 Pheanstalk github 页面上给出的 Usage Example 复制粘贴的:https://github.com/pda/pheanstalk。
我的composer.json文件的内容是:
{
"require": {
"pda/pheanstalk": "2.1.1"
}
}
编辑:
使用时的新错误:
use \Pheanstalk_Pheanstalk
错误:
Warning: The use statement with non-compound name 'Pheanstalk_Pheanstalk' has no effect in /opt/lampp/htdocs/project_zero/index.php on line 14
Fatal error: Class 'Pheanstalk' not found in /opt/lampp/htdocs/project_zero/index.php on line 17
【问题讨论】:
-
composer dump-autoload? -
@Arcesilas 我是否在终端中运行它并给你输出?我对 linux 和 composer 比较陌生
-
在终端运行它然后重试。
-
不过,它应该由 composer 在安装新包时自动运行。
-
@Arcesilas 我刚刚在终端中的 composer.json 文件位置运行它,输出为:
Generating autoload files。我尝试再次运行脚本,出现同样的错误
标签: php composer-php pheanstalk