Re: [RFC] Optional Catch Block Body
| From: | Christian Schneider | Date: | Thu, 31 Jul 2025 13:32:08 +0000 |
| Subject: | Re: [RFC] Optional Catch Block Body | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-128343@lists.php.net to get a copy of this message | ||
Am 31.07.2025 um 09:10 schrieb Rob Landers <rob@bottled.codes>:
> I can see something like this being useful in niche applications. For example, I have a proxy
> generation class that creates something like this:
>
> public function remoteCall() {
> $this->operation = nameof($this->remoteCall(...));
> $this->arguments = func_get_args();
> throw new SpecialException();
> }
>
> This SpecialException gets caught to let me know the application has consumed the one-use
> proxy. Using it looks something like
>
> rpc(fn(RemoteObject $o) => $o->remoteCall());
>
> which just provides type-safe rpc at the expense of some boilerplate.
>
> I also use empty exceptions to "jump" the stack when my framework knows there is
> nothing more to do until outside events happen. I think I could probably use fibers to do the same,
> but if the user is using a fiber library; there is no guarantee they'll play nice together.
> This is true with exceptions as well, but the user has direct control over exceptions (do not catch
> Throwable, for instance).
I'm not 100% sure I understood your examples but this smells like you are using exceptions for
flow (or maybe state?) control which I'm not sure I would encourage.
Regards,
- Chris