Proxy's `__debugInfo()` must not have side effects
- Dominant language
- PHP
- Stars
- 5.8k
- Forks
- 284
- PR merge metrics
- No merged PRs in 30d
Description
### Bug Report
| Q | A
|------------ | ------
| BC Break | yes/no
| Version | 2.12.3
#### Summary
I'm using Entity classes which have the magic `__debugInfo()` method defined. When I try to load a reference to a nonexistant Entity and `var_dump` it with the following code:
```php
$proxy = $em->getReference($my_classname, $this_id_does_not_exist);
var_dump($proxy);
```
the program dies
#### Current behavior
I get the following error (edited for readability):
```
PHP Warning: Uncaught Doctrine\ORM\EntityNotFoundException: Entity of type 'my_class' for IDs id(1) was not found in vendor/doctrine/orm/lib/Doctrine/ORM/EntityNotFoundException.php:33
Stack trace:
#0 vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php(139): Doctrine\ORM\EntityNotFoundException::fromClassNameAndIdentifier()
doctrine/orm#1 /tmp/cache/__CG__my_class.php(224): Doctrine\ORM\Proxy\ProxyFactory->Doctrine\ORM\Proxy\{closure}()
doctrine/orm#2 /tmp/cache/__CG__my_class.php(224): Closure->__invoke()
doctrine/orm#3 [internal function]: DoctrineProxies\__CG__\my_class->__debugInfo()
doctrine/orm#4 testscript.php(2): var_dump()
doctrine/orm#5 {main}
thrown in vendor/doctrine/orm/lib/Doctrine/ORM/EntityNotFoundException.php on line 33
PHP Fatal error: __debuginfo() must return an array in test.php on line 2
PHP Stack trace:
PHP 1. test() testscript.php:1
PHP 2. var_dump($value = class DoctrineProxies\__CG__\my_class { /*...*/ public $__initializer__ = class Closure { virtual $closure = "$this->Doctrine\ORM\Proxy\{closure}", }; public $__cloner__ = class Closure { virtual $closure = "$this->Doctrine\ORM\Proxy\{closure}", }; public $__isInitialized__ = FALSE }) testscript.php:2
PHP Fatal error: __debuginfo() must return an array in testscript.php on line 2
PHP Stack trace:
PHP 1. test() testscript.php:1
PHP 2. var_dump($value = class DoctrineProxies\__CG__\my_class { /*...*/ public $__initializer__ = class Closure { virtual $closure = "$this->Doctrine\ORM\Proxy\{closure}", }; public $__cloner__ = class Closure { virtual $closure = "$this->Doctrine\ORM\Proxy\{closure}", }; public $__isInitialized__ = FALSE }) testscript.php:2
```
#### How to reproduce
You need PHP 8 or greater and Xdebug loaded. Without xdebug, it works, and with xdebug it works in PHP 7.4 and below. I can try to make some minimal reproduction if it's necessary, for a quick reproduction, you can run the tests of https://github.com/flack/midgard-portable. The result will look like here: https://scrutinizer-ci.com/g/flack/midgard-portable/inspections/464a6111-e297-4cbb-9637-e90870531345
#### Expected behavior
It should work like it does in PHP 7.x
Contributor guide
Assessment
This issue has not been assessed yet.