On Tue, Apr 25, 2023, at 1:21 PM, Ilija Tovilo wrote:
> Hi Claude
>
>> > Hi all,
>> >
>> > I've submitted https://github.com/php/php-src/pull/11126 to add support 
>> > for final anonymous classes, though as noted by iluuu1994, it would 
>> > probably make more sense to just make all anonymous classes final by 
>> > default, what do you think?
>>
>> Extending an anonymous class is indeed possible (https://3v4l.org/pDFTL), 
>> but it is a hack as best. If someone wants a non-final class, could they not 
>> write a non-anonymous one? As a bonus, they wouldn’t need to instantiate the 
>> class before referencing it.
>
> Indeed. The argument was that, if you need to give the anonymous class
> a dedicated name through an alias to extend it, you might as well
> declare a named class in the first place.
>
> In case somebody finds benefit in making anonymous classes open, it
> seems more sensible to make them opt into openness, rather than
> applying this behavior to all anonymous classes that are used as final
> 99.9% of the time. Although I really don't think that is necessary.
>
> Ilija

I agree, but that would then require adding some kind of "non-final" keyword 
for anon classes to opt back out of finalness.  That's an extra complication I 
don't see as worth the effort to think through.

Until this thread it hadn't even occurred to me that you could extend an anon 
class at all, so the issue never came up.  And the apparent way to do so 
involves eval(), so I'm already afraid of it.  Given how edge-casey this is, 
I'd be inclined to just leave it be.

--Larry Garfield

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to