【发布时间】:2019-05-22 08:35:54
【问题描述】:
当我从另一个文件导入时,我的 autoload.php 没有加载所需的类:
这是我自动加载的类:
main.php:
use ElephantIO\Client;
use ElephantIO\Engine\SocketIO\Version2X;
require '/library/vendor/autoload.php';
class Main {
__construct() {
$this->socketIOClient = new Client(new Version2X('someWebsite'));
}
}
以下脚本有效:
require 'main.php';
$main = new Main();
但是这个脚本没有:
require '/library/vendor/autoload.php';
require 'main.php';
class NotWorking extends Thread {
__construct() {
$this->main = new Main();
}
}
$nowWorking = new NotWorking();
Output:
Fatal error: Uncaught Error: Class 'ElephantIO\Client' not found in main.php
为什么会这样,再次正确自动加载的方法是什么?
提前感谢您的帮助!
编辑:
问题是我使用的 pthreads 和扩展线程的类在需要 autoload.php 时表现不正常。
【问题讨论】:
-
我看不到第一个脚本是如何工作的。您正在尝试在包含自动加载之前使用一个类。应该是第一个脚本抛出错误
标签: php namespaces composer-php autoload