Re: [RFC] Lazy Objects
| From: | Arnaud Le Blanc | Date: | Thu, 27 Jun 2024 14:32:22 +0000 |
| Subject: | Re: [RFC] Lazy Objects | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-123939@lists.php.net to get a copy of this message | ||
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