-
-
Notifications
You must be signed in to change notification settings - Fork 189
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
ValueHolder proxy for class with accessing to private property within final method #472
Comments
Could you make an example of something triggering this, in the context of ProxyManager? |
I tried launch this code. It triggers error.
|
Interesting. I don't think that's fixable (the |
Trace:
I also tried to debug this code a bit and saw that php evaluate ClassWithFinalMethodAndPrivateProperty::finalMethod code with ProxyClass object as $this instead of call special inherited ClassWithFinalMethodAndPrivateProperty_123123::finalMethod like it does for non-final methods. |
Yeah, the issue here is that no initialisation can happen, so method calls cannot be redirected to the wrapped value. |
So it's pretty expected behavior, and ProxyManager users just should keep in mind that ValueHolder does not really good work with final methods? |
Well I would like also to tell my background story of this case. Hope it could be helpfully for people who google this problem. It happened when I use Symfony lazy service with final methods as described above. Symfony DI uses ValueHolder for lazy services so toggling off laziness fix the problem. Also code works fine when I declare property protected or make methods non final. Of course all final methods without accessing to private members could be evaluated too. |
A |
Do you mean ValueHolder should not support classes with |
Nono, it will be broken even in case of Try proxying this: class Counter
{
public $count = 0;
final public function increment () : int
{
return $this->count += 1;
}
public function decrement () : int
{
return $this->count -= 1;
}
}
$counter = makeProxy(Counter::class);
var_dump($counter->increment());
var_dump($counter->increment());
var_dump($counter->decrement()); This should print:
|
Actually, it may even work, now that I think of it (because of the |
Your code works okay.
But I see what do you mean, there is could be more problems with |
Let's re-open here to track the BC break to be introduced |
This issue can be fixed by duplicating the logic that ghost objects use: unset all properties on the virtual proxy and forward all access to them to the target object. |
I have class with accessing to private property within final method like this:
I get
Cannot access private property $prop
error if I call finalMethod on valueHolder proxy of this class.Is there such limitation for Value HolderProxy using or did I something wrong? Can't find any mentions about it in documentation or issues.
The text was updated successfully, but these errors were encountered: