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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't generate PHP 5.6 compatible autoloader - syntax error, unexpected '(' in autoload_real.php #10714

Closed
khromov opened this issue Apr 6, 2022 · 4 comments
Labels
Milestone

Comments

@khromov
Copy link
Contributor

@khromov khromov commented Apr 6, 2022

馃憢 We have an issue when trying to run composer install on a different PHP version than the target system (local environment uses PHP 8 but prod uses PHP 5.6)

The issue is that autoload_real.php generates this line:

\Composer\Autoload\ComposerStaticInita88cb81bddf628e1783485153a2bdd1f::getInitializer($loader)();

This causes a PHP error:

Parse error: syntax error, unexpected '(' in /var/www/vendor/composer/autoload_real.php on line 32

What we have done is to configure platform in composer.json:

"platform": {
  "php": "5.6"
}

I would then anticipate that a PHP 5.6-compatible autoloader would be generated. At the very least the autoloader code should not depend on the PHP version of the environment that triggers composer install.

This approach used to work up until some time ago, although I don't know at exactly which version it broke.

Output of composer diagnose:

Composer version: 2.3.3
PHP version: 5.6 - Package overridden via config.platform, actual: 8.1.4
PHP binary path: /usr/local/Cellar/php/8.1.4/bin/php

PS. I understand this is a niche problem, we are using a legacy environment and it's quite hard for us to run Composer in PHP 5.6, hence I'm creating this issue.

@stof
Copy link
Contributor

@stof stof commented Apr 6, 2022

Composer 2.3 requires PHP 7.2.5+, and so will not generate autoloading code compatible with older versions.

If you want the autoloader to be compatible with PHP 5.6, I think you need to stay on the Composer 2.2 LTS.

@khromov
Copy link
Contributor Author

@khromov khromov commented Apr 6, 2022

@stof Thanks so much for quickly pointing me to the right place, following the install guide and picking the 2.2 LTS at the end worked perfectly and generated a valid autoloader for PHP 5.6.

php composer-setup.php --version=2.2.11

@khromov khromov closed this as completed Apr 6, 2022
Seldaek added a commit that referenced this issue Apr 6, 2022
鈥ser or autoload.php with outdated PHP versions, fixes #10714, refs #10709
@Seldaek Seldaek added this to the 2.3 milestone Apr 6, 2022
@Seldaek Seldaek added the Bug label Apr 6, 2022
@Seldaek
Copy link
Member

@Seldaek Seldaek commented Apr 6, 2022

I took a look and it seems we really can easily support 5.6 still for autoloading purposes, so I fixed that in e0cce2b which will be available in 2.3.4 - hopefully you can then go back to using the latest Composer version :)

@jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Apr 7, 2022

This is awesome! Thank you so much! (this was actually the underlying reason behind my request the other day for the self-update --2.2 option ;-) )

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

4 participants