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

Wrong proxy class generation with default values as constants referncing self #988

Open
Lustmored opened this issue Sep 27, 2022 · 2 comments
Labels

Comments

@Lustmored
Copy link

Recent fix for constants in default parameter values broke proxy generation when constant is referenced as self.

Example entity code:

public function hasAccess(int $level = self::LEVEL_WORKER): bool
    {
        return $this->level >= $level;
    }

Generated proxy class:

public function hasAccess(int $level = \self::LEVEL_WORKER): bool
    {

        $this->__initializer__ && $this->__initializer__->__invoke($this, 'hasAccess', [$level]);

        return parent::hasAccess($level);
    }

Which in effect causes Fatal Error in PHP 8.1:

[27-Sep-2022 09:11:12 UTC] PHP Fatal error:  '\self' is an invalid class name in /app/var/cache/beta/doctrine/orm/Proxies/__CG__AppEntitySomeEntity.php on line 242
@malarzm
Copy link
Member

malarzm commented Sep 27, 2022

I'll start regretting introducing support for new in initializers... Sorry for the bug, we'll try to fix it hopefully this week

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Sep 28, 2022

Here is the code we use in Symfony to dump default values:
https://github.com/symfony/symfony/blob/6.2/src/Symfony/Component/VarExporter/ProxyHelper.php#L318

Feel free to borrow it (it's written for PHP >= 8.1)

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

4 participants