doctrine / doctrine/common

Wrong proxy class generation with default values as constants referncing `self`

Open
#988 2 comments 0 reactions 0 assignees View on GitHub
Bug
Dominant language
PHP
Stars
5.8k
Forks
284
PR merge metrics
No merged PRs in 30d

Description

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
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.