I had problems loading package I have required via composer
composer require package
PHP (version 5.6) said it did not recognised this package.
When looking into the scripts, I found in autoload_real.php these lines:
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION');
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitb5ab90658915f56241dbbea020198264::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$map = require __DIR__ . '/autoload_psr4.php';
echo "<br>";
var_dump($map);
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
}
My packages are listed inside the autoload_psr4.php file and are returned in the packages array but the code is going in to the if clause ($useStaticLoader is true) and in the autoload_static.php my package is not listed.
When setting $useStaticLoader to false, the else clause is loading my package as expected.
I'll add that the package I'm installing declare itself as a psr4 package.
What is the static flag mean and how can I make my package be listed in the autoload_static.php array?
Allow optionally disabling the static autoloader
The static autoloader presents a problem for environments where pre-PHP 5.6 syntax compatibility is required. Many projects have automated CI that runs a linter across all files in the repository to prevent developers from accidentally introdcing incompatible syntax. And while the static autoloader properly guards itself on lower PHP versions, it will still trip up linters. Given the number of bugs filed about this, it appears to be a common setup: #5255, #5316, #5324, and #5407.
This adds a --no-static option to the dump-autoload command, which will disable the static autoloader by updating autoload_real.php to not look for the file, and removes autoload_static.php if it exists.
Also you can avoid this using --optimize-autoloader flag with install / update.
P.S.: I had the same problems with php 5.6 too, check your path and namespaces twice!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With