"php fatal error: class 'myappchat' not found in /myapp/chat-server.php" Code Answer


The main path for the autoloading is the location of the composer.json file, so if that lives in /var/www/src/MyApp/, the autoloading will use that as a base.

In your case, you say the MyApp namespace can be found in the src directory (which means /var/www/src/MyApp/src). That's not true, since the file /var/www/src/MyApp/src/MyApp/Chat.php does not exists.

You can solve this issue in 3 different ways:

  • Moving composer.json - You can move the composer.json file to /var/www, to be able to use that as base;
  • Updating autoloading (using PSR-4) - You can also use PSR-4 instead of PSR-0 and configure it as "autoload": { "psr-4": { "MyApp\": "" } };
  • Reorganizing your files - You can also change the file structure to:

By Eric Freese on October 6 2022

Answers related to “php fatal error: class 'myappchat' not found in /myapp/chat-server.php”

Only authorized users can answer the search term. Please sign in first, or register a free account.