I have an issue running a function when use psr-4 autoloading.
When i declare directly which files should be in autoloading everything works fine. When i switch to psr-4 then i get log that the function is undefined.
src/cli.php:
namespace Php\Project1\Cli;
function run()
{
...
}
bin/brain-games:
#!/usr/bin/env php
<?php
$autoloadPath1 = __DIR__ . '/../../../autoload.php';
$autoloadPath2 = __DIR__ . '/../vendor/autoload.php';
if (file_exists($autoloadPath1)) {
require_once $autoloadPath1;
} else {
require_once $autoloadPath2;
}
use function Php\Project1\Cli\run;
run();
composer.json:
"autoload": {
"psr-4": {
"Php\\Project1\\": "src/"
}
},
The error that i get is:
PHP Fatal error: Uncaught Error: Call to undefined function Php\Project1\Cli\run() in /home/arkadiy/php-project1/bin/brain-games:15
Stack trace:
#0 {main}
thrown in /home/arkadiy/php-project1/bin/brain-games on line 15