symfony / polyfill

PHP polyfills

Home Page:https://symfony.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Collision between \Attribute of PrestaShop and \Attribute of polyfill-php80

yannicka opened this issue · comments

I have a PrestaShop module that has dependencies that include symfony/polyfill-php80.

And on some pages of the website, this is displayed to me because of that:

Compile Error: Class PrestaShop\PrestaShop\Adapter\Entity\Attribute may not inherit from final class (Attribute)

PrestaShop tries to extend the \Attribute class of the polyfill rather than that of PrestaShop. To avoid the collision between the class \Attribute of PrestaShop (which is not indicated in the error, but it exists) and the class \Attribute of the polyffill, I add this in the file composer.json :

"replace": {
    "symfony/polyfill-php80": "*"
}

However then I get the following error:

Symfony\Component\Debug\Exception\UndefinedFunctionException:
Attempted to call function "get_debug_type" from namespace "Symfony\Component\OptionsResolver".

  at modules/mon_module/vendor/symfony/options-resolver/OptionsResolver.php:1144
  [...]

What can I do?

This is an issue in Prestashop. See PrestaShop/PrestaShop#20710

Thanks. Until I can patch the code as long as the PR is open, is there anything I can do?

Prestashop is not compatible with PHP8 (because of name conflict with this class) and Symfony use PHP8's behaviors in many components (provided by either PHP 8 when installed or the polyfill).

The only thing you can do, is downgrading the components to a lower version. ie symfoy/option-resolver: ^5.0 as this component requiring php8 from version 5.1. https://packagist.org/packages/symfony/options-resolver#v5.0.11

Thanks, I've removed the dependency on friendsofphp/php-cs-fixer for now, I'll see how to restore it later.

Yep I encountered the same issue while upgrading some packages in my Prestashop app. But it turns out you don't necessarily have to downgrade your packages, you can simply set a highest version constraint for the polyfill as mentioned here, e.g:
"symfony/polyfill-php80": "<=1.18.1"

This should be ok for now cause the majority of dependents packages does not require a higher version, and I didn't personally encountered any usage of that Attribute class in a symfony package at the moment, except a use statement in service-contracts that was recently removed.

But it definitely will be a pain for us poor legacy Prestashop users in the future if this class is used (or if we ever want to use php8 for that matter), simply because a lot of modules are using this class and they would cease to work without some obscure wizzardy involved.