Composer: Undefined Method Related To Global Install

I just updated the Aura v2 libraries to use PSR-4 via Composer instead of their custom autoload.php files, but when I started my integration tests for the Aura.Project_Kernel, I got this error:

PHP Fatal error:  Call to undefined method ComposerAutoloadClassLoader::setPsr4() in /Users/pmjones/Code/auraphp/develop-2-projects/Aura.Project_Kernel/cli-project/vendor/composer/autoload_real.php on line 38

Even after a composer self-update the problem remained.

It turns out the problem was related to having issued composer global require phpunit/phpunit=3.7.*. The various Composer global vendor files were overriding the local ones in the project. I discovered this only by calling var_dump(get_included_files()) in the project-specific autoload_real.php file.

I ended up deleting ~/.composer (the global Composer location) and re-installing PHPUnit, but looking back on it, perhaps a composer global update would have solved the problem as well.

UPDATE: Christophe Coevet in the comments indicates composer global dump-autoload would have done the trick as well.

Are you stuck with a legacy PHP application? You should buy my book because it gives you a step-by-step guide to improving your codebase, all while keeping it running the whole time.
Share This!Share on Google+Share on FacebookTweet about this on TwitterShare on RedditShare on LinkedIn

2 thoughts on “Composer: Undefined Method Related To Global Install

  1. Updating the global vendors would not even be necessary. Re-dumping the global autoloader would have been enough to make it use the newer version of the ClassLoader: “composer global dump-autoload“

Leave a Reply

Your email address will not be published. Required fields are marked *