composer.json allows nikic/php-parser ^4.0 but Extractor requires ^5.0 (uses createForVersion)
composer.json allows nikic/php-parser ^4.0 but Extractor requires ^5.0 (uses createForVersion)
Problem description
In Extractor, we are using the method PhpParser\ParserFactory::createForVersion.
You can see the usage here:
PHPFileExtractor.php#L36
This method was added in nikic/php-parser starting from version 5.0+.
However, the composer.json file of php-translation/extractor currently allows lower versions:
"nikic/php-parser": "^4.0 || ^5.0",
Composer may therefore install nikic/php-parser 4.x, which does not have the createForVersion method. This leads to a runtime error when using the Extractor with a 4.x version of nikic/php-parser.
See composer.json entry here: composer.json#L13
Suggested solution
Update the dependency in composer.json to require only version ^5.0 of nikic/php-parser, e.g.:
"nikic/php-parser": "^5.0",
This will prevent Composer from installing incompatible 4.x versions and avoid runtime errors.