E
E
Enfiladed2019-09-25 21:15:37
Composer
Enfiladed, 2019-09-25 21:15:37

Why doesn't Composer see the namespace?

Good afternoon, there is a project where you need to use Ratchet (php library for web sockets). It is downloaded via composer, I have never used it before, that's the problem. I can not understand why the namespace is not visible from another file. Here is the structure:
5d8bad1307275802842040.png
Composer.json:

{
   "autoload": {
        "psr-4": {
            "App\\": "src",
        }
    }
   ...
}

In chat.php
namespace App;
class Chat implements MessageComponentInterface { ...
}

In server.php
use App\Chat;
$chat =  new Chat();

And an error occurs when starting server.php (here is only the main one, so the lines in the error are different)
Fatal error: Uncaught Error: Class 'App\Chat' not found in D:\P\Xampp\htdocs\chat\server\src\server.php:10 Stack trace: #0 {main} thrown in D:\P\Xampp\htdocs\chat\server\src\server.php on line 10

Roughly speaking, for some reason, the class from chat.php is not visible in server.php. I didn’t write much in php before, but I seemed to be doing everything right, people are still the same. If anyone knows what the problem is, please help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Komarov, 2019-09-25
@Lisey

PSR-4

"psr-4": {
    "App\\": "src/"
}

And capitalized class file names (Chat.php, Server.php)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question