Re: [RFC] Throwable Hierarchy Policy for Extensions
| From: | Larry Garfield | Date: | Mon, 28 Apr 2025 22:36:32 +0000 |
| Subject: | Re: [RFC] Throwable Hierarchy Policy for Extensions | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-127235@lists.php.net to get a copy of this message | ||
On Mon, Apr 28, 2025, at 4:27 PM, Tim Düsterhus wrote:
> Hi
>
> On 4/28/25 23:09, Larry Garfield wrote:
>>>> * Would allowing an extension-tagging interface instead of a base class be an
>>>> option? It still allows for catching "anything thrown by this extension", which I presume
>>>> is the goal. If not, why?
>>>
>>> See the “Choice of Base Exception” section in
>>> https://github.com/php/php-src/pull/9220.
>>
>> That seems to be about not having a common interface for both the Error and the Exception,
>> which makes sense. I'm talking about
interface ExampleException
>> {} and interface ExampleError {}, instead of
>> class ExampleException extends Exception {}, etc.
>
> Besides not following the de facto standard (which is what this proposal
> is trying to codify), I'm also not sure what benefit an interface would
> have over a base exception for the problem we're trying to solve here?
> So I can return the “why (interface)?”. It would just make it tempting
> to extend some SPL exception :-)
It's a common recommendation in userland, as it allows implementers to extend an existing
exception (eg, InvalidArgumentException) of their choice while still being tagged as coming from a
given library. Though I suppose if the policy doc also says to never do that, that becomes an
irrelevant consideration.
--Larry Garfield