Re: [Pre RFC] Automated delegation using implements by
| From: | Rowan Tommins [IMSoP] | Date: | Thu, 01 Oct 2026 21:21:05 +0000 |
| Subject: | Re: [Pre RFC] Automated delegation using implements by | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-132767@lists.php.net to get a copy of this message | ||
Hi all,
On 1 October 2026 14:49:38 BST, Larry Garfield <larry@garfieldtech.com> wrote:
>However, that example also highlights the main limitation of the current proposal: Many of the
>methods are fluent, returning $this.
This is where I've always stumbled when trying to come up with similar feature proposals - when
you start looking for use cases, a lot of them need *just one small thing* on top of the forwarded
call. So you add an extra keyword here, and a special logic there, and eventually it no longer feels
like an elegant shorthand at all.
Looking at the Laravel FluentPromise example James shared, I'm not sure if it's quite the
same handling of $this that you're describing; so would we need multiple different keywords to
describe exactly how the return value should be manipulated?
I've written decorator classes that exist only to catch exceptions from the real method and log
them to a specific channel. Most of the code is boilerplate passing along the arguments and return
values. I can't just say "delegate all these methods" at the class level, but
I'd quite like some inline syntax for "forward call to $this->wrapped".
But then again, there are cases where you want to forward *all except one* argument, or forward all
arguments but add an extra flag, and so it goes on.
The best I can think of is something inspired by Aspect Oriented Programming: forward these calls,
but decorate them with these pre- and post-actions. But I've not managed anything that
doesn't look like an obfuscated version of the original code.
Regards,
Rowan Tommins
[IMSoP]