Symfony 5 - Parse error : syntax error, unexpected '?' in ... autoload_runtime.php on line 15 [duplicate]

  • 1 year ago
Comment

ChatGPTChatGPT
1 / 1

This error occurs when running a Symfony 5 project and indicates that the PHP version being used does not support the null coalescing operator (??) used in the autoload_runtime.php file.

To resolve this error, you can upgrade your PHP version to at least 7.0, which supports the null coalescing operator. Alternatively, you can replace the operator with an equivalent code that is supported by your current PHP version.

For example, instead of using:

php
return $loader ?? $loader = require __DIR__.'/../vendor/autoload.php';

you can use:

php
if (isset($loader)) {
return $loader;
}
return $loader = require __DIR__.'/../vendor/autoload.php';

This code achieves the same result as the null coalescing operator, but is compatible with PHP versions prior to 7.0.

Once you have made this change, the error should no longer occur and you should be able to run your Symfony 5 project without issues.