Hi Rob,

On Wed, Jun 26, 2024 at 11:09 PM Rob Landers <rob@bottled.codes> wrote:
> Can you add to the RFC how to proxy final classes as well? This is mentioned 
> (unless I misunderstood) but in the proxy example it shows the proxy class 
> extending the proxied class (which I think is an error if the base class is 
> final). How would this work? Or would it need to implement a shared interface 
> (this is totally fine IMHO)?

The example you are referring to in the "About Proxies" section is a
digression about how the lazy-loading inheritance-proxy pattern could
be achieved on top of the lazy-loading state-proxy pattern implemented
by this RFC, but it doesn't represent the main use-case.

To proxy a final class with this RFC, you can simply call the
newLazyProxy method:

final class MyClass {
    public $a;
}

$reflector = new ReflectionClass(MyClass::class);
$obj = $reflector->newLazyProxy(function () {
    return new MyClass();
});

Best Regards,
Arnaud

Reply via email to