On Fri, 5 May 2023 at 23:58, Levi Morrison via internals <internals@lists.php.net> wrote: > > I am not sure about making them final by default. I think it's a more > consistent language design to allow `new final class()` as you > originally proposed. Although I don't know why anyone would want to > extend anonymous classes, we can see that people do, in fact, do it. I > don't see why we couldn't allow `new class() extends $someClass` in > the future to specifically allow them to do this. I mean, I'm not > going to lobby for it, I'm just pointing out that is more aligned and > consistent with other parts of the language, than to simply make it > final by default. > > Cheers. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php >
My work currently is integrating with various shipping provider APIs such as DHL. I have to deal with the enormous API request (and response) definitions. I am just creating a DTO class for each level of JSON key, which results in a HUGE amount of classes. I have a hunch this problem can be solved better with anonymous classes, but their support is not great yet - PHPStorm has a breaking bug with their autocompletion and I am too dumb to figure out a better solution in any case. However, I totally agree with Levi in that the way forward is better towards `new class() extends $someClass` and not "all anonymous classes final by default". It may open patterns and opportunities we have yet to think about. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php