-
-
Notifications
You must be signed in to change notification settings - Fork 288
Description
Recently I came across an issue that was hard to debug and quite unexpected to me.
Code like the one below, which is fully valid PHP code
class Foo {
/**
* @ORM\ManyToOne()
*/
private Foo $parent;
... // Always initialize $this->parent in constructor
public function doSomething(): void {
var_dump($parent->parent);
}
}will result in Typed property accessed before initialization error.
The situation is even worse with nullable properties which will simply return NULL which is pretty hard to spot.
I understand that it's an internal limitation of how currently proxy classes work BUT support for public properties has been added in 2.4 if I recall correctly.
I was not able to find this issue documented anywhere so I'd either:
- Add visible warning in the documentation to never access private properties directly from the same class.
- Handle private/protected properties the same way as public properties are currently handled
Also, since I've seen plans to move from custom implementation of Proxies to https://github.com/Ocramius/ProxyManager (doctrine/orm#8518), is it possible that this transition will resolve this issue?