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

Fatal error if composer prepend-autoloader is set to false #1497

Closed
legoktm opened this issue Jun 6, 2017 · 3 comments
Closed

Fatal error if composer prepend-autoloader is set to false #1497

legoktm opened this issue Jun 6, 2017 · 3 comments
Milestone

Comments

@legoktm
Copy link
Contributor

legoktm commented Jun 6, 2017

To reproduce, create a composer.json with:

{
	"require": {
		"squizlabs/php_codesniffer": "dev-master"
	},
	"config": {
		"prepend-autoloader": false
	}
}

Run composer install. Then try vendor/bin/phpcs --version. I get the following output:

PHP Fatal error:  Uncaught Error: Class 'Composer\Autoload\ClassLoader' not found in /home/km/projects/sandbox/phpcs-test/vendor/composer/autoload_real.php:23
Stack trace:
#0 /home/km/projects/sandbox/phpcs-test/vendor/autoload.php(7): ComposerAutoloaderInit0b88db96a6b16f1b2f158f8142d34d63::getLoader()
#1 /home/km/projects/sandbox/phpcs-test/vendor/squizlabs/php_codesniffer/autoload.php(73): include('/home/km/projec...')
#2 [internal function]: PHP_CodeSniffer\Autoload::load('Composer\\Autolo...')
#3 /home/km/projects/sandbox/phpcs-test/vendor/composer/autoload_real.php(23): spl_autoload_call('Composer\\Autolo...')
#4 /home/km/projects/sandbox/phpcs-test/vendor/autoload.php(7): ComposerAutoloaderInit0b88db96a6b16f1b2f158f8142d34d63::getLoader()
#5 /home/km/projects/sandbox/phpcs-test/vendor/squizlabs/php_codesniffer/autoload.php(73): include('/home/km/projec...')
#6 [internal function]: PHP_CodeSniffer\Autoload::load('PHP_CodeSniffer...')
#7 /home/km/projects/sandbox/phpcs-test/vendor/squizlabs/php_codesniffer/bin/phpcs(17): s in /home/km/projects/sandbox/phpcs-test/vendor/composer/autoload_real.php on line 23

I found this when testing upgrading MediaWiki's CodeSniffer ruleset to 3.0. MediaWiki sets prepend-autoloader: false for performance reasons since most of our autoloaded classes are in MediaWiki's autoloader, not composer's.

@legoktm
Copy link
Contributor Author

legoktm commented Jun 29, 2017

Here's what's happening:

  • PHPCS autoloader installed
  • PHP_CodeSniffer\Autoload::load() called, which tries to initialize composer's autoloader
  • Composer autoloader registers itself last, then tries to autoload a Composer class
  • PHPCS autoloader tries to find it, can't, and then somewhere along the way it gives up and an exception is thrown

I wonder if this is a composer bug in that the loading of \Composer\Autoload\ClassLoader should not be controlled by prepend-autoloader.

legoktm added a commit to legoktm/PHP_CodeSniffer that referenced this issue Jun 29, 2017
If the composer autoloader has prepend-autoloader: false set, the PHPCS
autoloader will take priority over the composer autoloader, and composer
will have trouble autoloading its own autoloader.

Avoid all of that by simply not trying to load any classes that are
under the "Composer" namespace.

Fixes squizlabs#1497
legoktm added a commit to legoktm/PHP_CodeSniffer that referenced this issue Jun 29, 2017
If the composer autoloader has prepend-autoloader: false set, the PHPCS
autoloader will take priority over the composer autoloader, and composer
will have trouble autoloading its own autoloader.

Avoid all of that by simply not trying to load any classes that are
under the "Composer" namespace.

Fixes squizlabs#1497
legoktm added a commit to legoktm/PHP_CodeSniffer that referenced this issue Jul 6, 2017
If the composer autoloader has prepend-autoloader: false set, the PHPCS
autoloader will take priority over the composer autoloader, and composer
will have trouble autoloading its own autoloader.

Avoid all of that by simply not trying to load any classes that are
under the "Composer" namespace.

Fixes squizlabs#1497
@paladox
Copy link
Contributor

paladox commented Jul 8, 2017

bump.

@gsherwood hi, could you take a look at this please?

@gsherwood gsherwood changed the title Fatal error if composer prepend-autoloader: false config set Fatal error if composer prepend-autoloader is set to false Jul 13, 2017
gsherwood added a commit that referenced this issue Jul 13, 2017
@gsherwood gsherwood added this to the 3.0.2 milestone Jul 13, 2017
@gsherwood
Copy link
Member

Fixed via PR #1536

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

No branches or pull requests

3 participants