1
得到錯誤的棘輪簡單的例子:NameScape錯誤。停留在 'MyApp的聊天'
Fatal error: Uncaught Error: Class 'MyApp\Chat' not found
我的文件結構是這樣的:
root\composer.json
root\bin\chat-server.php
root\src\MyApp\Chat.php
Composer.json是
{
"autoload": {
"psr-0": {
"MyApp": "src"
}
},
"require": {
"cboden/ratchet": "0.3.*"
}
}
聊天-server.php是
<?php
use Ratchet\Server\IoServer;
use MyApp\Chat;
require dirname(__DIR__) . '/vendor/autoload.php';
$server = IoServer::factory(
new Chat(),
8080
);
$server->run();
和Chat.php是
<?php
namespace MyApp;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
class Chat implements MessageComponentInterface {
public function onOpen(ConnectionInterface $conn) {
}
public function onMessage(ConnectionInterface $from, $msg) {
}
public function onClose(ConnectionInterface $conn) {
}
public function onError(ConnectionInterface $conn, \Exception $e) {
}
}
我曾嘗試以下,但還是現在工作: PHP Fatal error: Class 'MyApp\Chat' not found in /MyApp/chat-server.php
你可以做'print_r(get_declared_classes());'並且看看它是否被加載到不同的命名空間下? –
您是否嘗試過使用composer dump-autoload – Maris