laravel-opcache icon indicating copy to clipboard operation
laravel-opcache copied to clipboard

Cannot pass symfony/polyfill-intl-idn under PHP 7.4

Open wilbur-yu opened this issue 3 years ago • 4 comments

php version: 7.4.14

php artisan opcache:compile --force=true
PHP Parse error:  syntax error, unexpected '|', expecting '{' in /Users/wilbur.yu/MyCode/Work/qingyan/vendor/symfony/polyfill-intl-normalizer/bootstrap80.php on line 18

Parse error: syntax error, unexpected '|', expecting '{' in /Users/wilbur.yu/MyCode/Work/qingyan/vendor/symfony/polyfill-intl-normalizer/bootstrap80.php on line 18
[1]    86000 segmentation fault  php artisan opcache:compile --force=true

wilbur-yu avatar Jan 11 '21 11:01 wilbur-yu

This seems to happen at https://github.com/appstract/laravel-opcache/blob/d2ce88cddda6af54c14d1f9ceaaf94b54f38f9d3/src/OpcacheClass.php#L70

because polyfill files that require php 8 syntax are being parsed.

For now I've simply run php artisan vendor:publish --provider="Appstract\Opcache\OpcacheServiceProvider" --tag="config" to publish the config file and added the following to exclude:

'exclude' => [
        ...
        ...
        'symfony/polyfill-ctype',
        'symfony/polyfill-iconv',
        'symfony/polyfill-intl-grapheme',
        'symfony/polyfill-intl-idn',
        'symfony/polyfill-intl-normalizer',
        'symfony/polyfill-mbstring',
        'symfony/polyfill-php80'
    ],

Not a definitive solution but for now it works!

lorenzocattaneo avatar Jan 13 '21 11:01 lorenzocattaneo

Any updates soon @ovanschie ? :)

jonathan-bird avatar Feb 15 '21 23:02 jonathan-bird

The easy but not very viable solution is use php 8.

AEmad01 avatar Mar 25 '21 16:03 AEmad01

I've spent some time digging into this today, and this appears to impact anyone running on PHP 7.x (7.4, in my case):

When iterating over the found files, opcache_compile_file() trips up on the bootstrap80.php files included within the various symfony/polyfill-* packages, as they use PHP 8.x-specific syntax (the polyfill packages themselves are a dependency of swiftmailer/swiftmailer, which is itself a dependency of laravel/framework).

Normally this wouldn't be a problem, as the Symfony packages only load these files when running on PHP 8.x. However, the list of files doesn't know about this, so we attempt to inject PHP 8.x syntax into a PHP 7.x OPcache and everything goes sideways.

The solution @lorenzocattaneo works as a short-term fix, but ultimately it's excluding everything in those symfony/polyfill-* packages from getting pre-loaded. @wojo1206's work in #125 would let us target specific files (as opposed to whole directories), which would be beneficial, but ultimately some better error handling within OpcacheClass::compile() is needed to prevent issues like this from breaking the whole process.

stevegrunwell avatar Apr 07 '21 01:04 stevegrunwell