0
I registered the autoload in the composer.json
"autoload": {
"psr-4": {
"Racioly\\MeuPackage\\": "src/"
}
}
I created a folder called test at the root of the project, and also created a file teste.php, this file contains the following code:
require_once __DIR__ . '/../vendor/autoload.php';
use Racioly\MeuPackage\Complex;
var_dump(new Complex(2110));
Within src I have the class Complex:
namespace Complex;
class Complex {
...
}
But when I run the file through the terminal php teste.php get the bug:
PHP Fatal error: Uncaught Error: Class 'Racioly Meupackage Complex' not found in ... test.php:7
which is exactly where I test the instance of Complex in the var_dump()
Your class
complexthis important the namespaceComplex, however, in Composer you are setting that the foldersrchas the origin of the namespaceRacioly\MeuPackage\. In classComplexyou need it important for this namespace. Read more about https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md– juniorb2ss