1
erreur dans Ratchet Exemple simple:Erreur NameScape. Coincé dans 'MyApp Chat' Obtenir
Fatal error: Uncaught Error: Class 'MyApp\Chat' not found
Ma structure du fichier est comme:
root\composer.json
root\bin\chat-server.php
root\src\MyApp\Chat.php
Composer.json est
{
"autoload": {
"psr-0": {
"MyApp": "src"
}
},
"require": {
"cboden/ratchet": "0.3.*"
}
}
le chat -server.php est
<?php
use Ratchet\Server\IoServer;
use MyApp\Chat;
require dirname(__DIR__) . '/vendor/autoload.php';
$server = IoServer::factory(
new Chat(),
8080
);
$server->run();
et Chat.php est
<?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) {
}
}
J'ai essayé la suite, mais fonctionne maintenant: PHP Fatal error: Class 'MyApp\Chat' not found in /MyApp/chat-server.php
Pouvez-vous faire 'print_r (get_declared_classes());' et voir s'il est chargé sous un autre espace de noms? –
Avez-vous essayé composer dump-autoload – Maris