Composer autoload always comes first

核能气质少年 提交于 2019-12-09 03:50:26

Ok, guys, I found the solution and want to share it with you: the spl_autoload_register() function has a third parameter: $prepend. When set to true, it will prepend the autoload function to the autoload queue, instead of appending it (it's actually documented at the official PHP Documentation). Composer always sets it to true, so that its autoloader is always called first. To fix it, I changed the legacy autoloader, setting $prepend to true, and called it AFTER including composer's autoload.

Hope it helps someone! :)

Pass true as a third argument to the spl_autoload_register:

spl_autoload_register(your_autoload_func(), true, true);

You need to be aware that composer use different ways to include php files, check vendor/composer/autoload_real.php for details, and remember that composer can include files directly in the place where you include

require_once('vendor' . DIRECTORY_SEPARATOR . 'autoload.php');

so if you are lucky to have vendor/composer/autoload_static.php remember that adding $prepend parameter to your own spl_autoload_register() may not be enough.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!