Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call to undefined method Composer\Autoload\ClassLoader::setPsr4() #2553

Closed
Anahkiasen opened this issue Jan 6, 2014 · 8 comments
Closed
Labels

Comments

@Anahkiasen
Copy link

I was trying to do a test PSR4 package for myself, I have the latest version of Composer. However after running composer install with the following autoload directive :

"autoload": {
    "psr-4": {
        "Warkham\\": "src"
    }
},

When including vendor/autoload.php I'm getting the following error :

PHP Fatal error:  Call to undefined method Composer\Autoload\ClassLoader::setPsr4() in /Users/anahkiasen/Sites/autopergamene/warkham/vendor/composer/autoload_real.php on line 36
PHP Stack trace:
PHP   1. {main}() /Users/anahkiasen/.composer/vendor/phpunit/phpunit/composer/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /Users/anahkiasen/.composer/vendor/phpunit/phpunit/composer/bin/phpunit:63
PHP   3. PHPUnit_TextUI_Command->run() /Users/anahkiasen/.composer/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:126
PHP   4. PHPUnit_TextUI_Command->handleArguments() /Users/anahkiasen/.composer/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:135
PHP   5. PHPUnit_TextUI_Command->handleBootstrap() /Users/anahkiasen/.composer/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:596
PHP   6. PHPUnit_Util_Fileloader::checkAndLoad() /Users/anahkiasen/.composer/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:756
PHP   7. PHPUnit_Util_Fileloader::load() /Users/anahkiasen/.composer/vendor/phpunit/phpunit/PHPUnit/Util/Fileloader.php:77
PHP   8. include_once() /Users/anahkiasen/.composer/vendor/phpunit/phpunit/PHPUnit/Util/Fileloader.php:93
PHP   9. require() /Users/anahkiasen/Sites/autopergamene/warkham/tests/WarkhamTestCase.php:4
PHP  10. ComposerAutoloaderInit1715e0360e80b7f7434edb0d52b414a4::getLoader() /Users/anahkiasen/Sites/autopergamene/warkham/vendor/autoload.php:7

Tried doing composer self-update but nothing :

➜  warkham git:(master) ✗ composer selfupdate
You are already using composer version 76833335152d17632e1afe277a9edbbb232d3a1f.

Am I doing something wrong or ? I checked the vendor/composer/ClassLoader.php class and it does have a setPsr4 method which is even weirder.

@Seldaek
Copy link
Member

Seldaek commented Jan 6, 2014

PHPUnit's classloader is loaded before the local one and the class is outdated there it seems, so you should do a composer global dump to update that autoloader then it should be fine.

@Seldaek Seldaek closed this as completed Jan 6, 2014
@ghost
Copy link

ghost commented Jan 8, 2014

Sorry to drag this back up again, but I'm having a similar issue and running composer global dump as mentioned above yields the following:

Changed current directory to /home/craw/.composer

  [InvalidArgumentException]                                  
  Command "dump" is ambiguous (dump-autoload, dumpautoload).  

global command-name [args1] ... [argsN]

Obviously I tried running composer dump-autoload to no avail. Furthermore, the error I get is different, in that it does not include PHPUnit's stack trace.

$ phpunit -c Tests/phpunit.xml 
PHP Fatal error:  Call to undefined method Composer\Autoload\ClassLoader::setPsr4() in /home/craw/public_html/Project/vendor/composer/autoload_real.php on line 40

Fatal error: Call to undefined method Composer\Autoload\ClassLoader::setPsr4() in /home/craw/public_html/Project/vendor/composer/autoload_real.php on line 40

@Seldaek
Copy link
Member

Seldaek commented Jan 8, 2014

The ambiguous command issue is a regression in symfony that's been fixed already, it will be in composer as soon as they release.

The rest, it looks like whatever autoloader phpunit uses is still the old one, maybe it wasn't installed with composer global but in some other way? Just try to re-dump the autoloader in your phpunit

@ghost
Copy link

ghost commented Jan 8, 2014

Oh, right. I was using my personal installation of PHPUnit instead of the one required by composer, which does work. I should have thought of that. Thanks.

@ioleo
Copy link

ioleo commented Jun 11, 2014

@Seldaek sorry to dig it up, but also have this problem:

loostro@Skipper:~/Projekty/prognozy$ phpunit -c app
PHP Fatal error:  Call to undefined method Composer\Autoload\ClassLoader::setPsr4() in /home/loostro/Projekty/prognozy/vendor/composer/autoload_real.php on line 33
PHP Stack trace:
PHP   1. {main}() /usr/local/lib/phpunit/vendor/phpunit/phpunit/composer/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /usr/local/lib/phpunit/vendor/phpunit/phpunit/composer/bin/phpunit:63
PHP   3. PHPUnit_TextUI_Command->run() /usr/local/lib/phpunit/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:129
PHP   4. PHPUnit_TextUI_Command->handleArguments() /usr/local/lib/phpunit/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:138
PHP   5. PHPUnit_TextUI_Command->handleBootstrap() /usr/local/lib/phpunit/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:606
PHP   6. PHPUnit_Util_Fileloader::checkAndLoad() /usr/local/lib/phpunit/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:778
PHP   7. PHPUnit_Util_Fileloader::load() /usr/local/lib/phpunit/vendor/phpunit/phpunit/PHPUnit/Util/Fileloader.php:76
PHP   8. include_once() /usr/local/lib/phpunit/vendor/phpunit/phpunit/PHPUnit/Util/Fileloader.php:92
PHP   9. require_once() /home/loostro/Projekty/prognozy/app/bootstrap.php.cache:3
PHP  10. require() /home/loostro/Projekty/prognozy/app/autoload.php:5
PHP  11. ComposerAutoloaderInit0fd3c5178a91b0785080bdcaf7c37958::getLoader() /home/loostro/Projekty/prognozy/vendor/autoload.php:7

Then I googled and found this issue, however it didn't help:

loostro@Skipper:~/Projekty/prognozy$ composer global dump
Changed current directory to /home/loostro/.composer
Composer could not find a composer.json file in /home/loostro/.composer
To initialize a project, please create a composer.json file as described in the http://getcomposer.org/ "Getting Started" section

I've got composer installed globally. The ~/Projekty/prognozy directory is my symfony2 project root directory:

loostro@Skipper:~/Projekty/prognozy$ ls -l
razem 256
drwxr-x---  6 loostro www-data   4096 maj  6 01:56 app
drwxrwxr-x  7 loostro loostro    4096 maj  6 00:01 assets
drwxr-x---  2 loostro www-data   4096 maj  6 01:21 bin
-rwxrwxr-x  1 loostro loostro    3569 maj 19 17:44 composer.json
-rw-rw-r--  1 loostro loostro  166441 maj  6 01:56 composer.lock
drwxr-x--- 13 loostro www-data   4096 maj  5 23:12 web
drwxr-x---  3 loostro www-data   4096 sty 10 16:04 src
drwxr-x--- 40 loostro www-data   4096 maj  6 01:56 vendor

(removed the text files from the list for brevity)

What's wrong? Any ideas how to fix this?

@stof
Copy link
Contributor

stof commented Jun 11, 2014

well, your phpunit is installed in /usr/local/lib/phpunit, not in the composer global folder. So this is the place where you need to go run the dump-autoload command to make it use the newer autoloader

@ioleo
Copy link

ioleo commented Jun 11, 2014

Thanks @stof ! Indeed going to /usr/local/lib/phpunit and running sudo composer dump-autoload command fixed the problem.

@akky
Copy link

akky commented Jun 19, 2015

I am seeing the same error on WordPress. I realized that on the app having plugin system like WordPress, different plugins could autoload different Composer autoloader under their vendor/composer directories,and if the first-loaded one is using rather old autoloader (which did not support psr4), the latter one (likely set-up with newer Composer) cause this error.

I have not found the solution yet, just record this here for someone will see the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants