Skip to content

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

@khromov

Description

@khromov

👋 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions