Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Scoped] Symfony Polyfills are incorrectly prefixed #5617

Closed
mkrauser opened this issue Feb 18, 2021 · 10 comments
Closed

[Scoped] Symfony Polyfills are incorrectly prefixed #5617

mkrauser opened this issue Feb 18, 2021 · 10 comments
Labels

Comments

@mkrauser
Copy link

mkrauser commented Feb 18, 2021

Bug Report

Subject Details
Rector version e.g. v0.9.29
Installed as prefixed Rector

I got an exception, that the function get_debug_type is not defined. I tracked it down to the symfony polyfills incorrectly being prefixed.

The only solution I found to fix this, is to whitelist all bootstrap.php files and bootstrap80.php files within the polyfills. whitelist-global-functions does not work. This might also be an issue within php-scoper itself.

Here's the polyfill for get_debug_type defined: https://github.com/rectorphp/rector-prefixed/blob/f907c6d2101d9e34d027f59a43e5efa1db76790e/vendor/symfony/polyfill-php80/bootstrap.php#L50

If rector is executed on PHP < 8.0, and get_debug_type is called (either by rector- or by vendor-code), the function is undefined due to the namespace added here.

@mkrauser mkrauser added the bug label Feb 18, 2021
@TomasVotruba
Copy link
Member

TomasVotruba commented Feb 18, 2021

Hi,

thanks for reporting!
Could you link to the code in https://github.com/rectorphp/rector-prefixed ?

How can we reproduce with rector/rector-prefixed?

@mkrauser
Copy link
Author

Of course. I added it to the report

@TomasVotruba
Copy link
Member

There is no get_debug_type in the linked file.

@TomasVotruba
Copy link
Member

We'll need a reproducible repository on Github to solve this one

@mkrauser
Copy link
Author

We'll need a reproducible repository on Github to solve this one

I've updated the description and I'll try to implement a failing demo

@TomasVotruba
Copy link
Member

Thanks!
Now it's hard to follow where the reply is. Could you use comments for next replies to keep the context from up to bottom?

@mkrauser
Copy link
Author

Of course, I just wanted to keep everything in one place.
It might take a few days before I find time to do that.

@TomasVotruba
Copy link
Member

TomasVotruba commented Feb 19, 2021

This looks like bug in php-scoper, as the function itself is prefixed correctly:

// bug
if (!\function_exists('get_debug_type')) {
    function get_debug_type($value) : string
    {
        // correct
        return \RectorPrefix20210218\Symfony\Polyfill\Php80\Php80::get_debug_type($value);
    }
}

There are 2 ways to fix it:

  • Right in php-scoper (better, but could take weeks to merge)
  • Add a custom patcher callback in our scoper.php to handle it:
    ScoperOption::PATCHERS => [

@mkrauser
Copy link
Author

There is already an issue in php-scoper for this: humbug/php-scoper#440

@TomasVotruba
Copy link
Member

Closing here then, thanks for reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants