On Tue, Feb 24, 2015 at 12:21 PM, Mike Willbanks <pen...@gmail.com> wrote: > > > On Tue, Feb 24, 2015 at 7:52 AM, Philip Sturgeon <pjsturg...@gmail.com> > wrote: >> >> Good day! >> >> https://wiki.php.net/rfc/anonymous_classes >> >> There's a little RFC + patch that Joe Watkins put together, and as >> before with the ArrayOf RFC, I'll be helping out. >> >> So, lets get this discussion rolling. >> >> It was declined for PHP 5 some time ago, and has returned now to try for >> PHP 7. >> >> The usage of anonymous classes to some will be instantly offensive, >> but really it comes down to the use case. The usage of anonymous >> functions compared to declared functions is pretty much the exact same >> thing as anonymous classes. >> >> Other than examples on the RFC, Fractal would certainly be happy to >> have them: http://fractal.thephpleague.com/transformers/ > > > I would also find myself to be a very happy consumer of this. It can > provide the opportunity of getting rid of a large amount of boilerplate. In > addition, there has been several times when implementing single use > extensions for say view libraries (Plates extensions comes to mind) or > Plugin handling for things like Zend Framework 2 and there has been several > times I utilize a closure with an array to get around having an object > simply due to you want to have a callback but with some form of definition. > I think there is a very large use case here and something that would be a > great addition to the language. Sure, I could make a class and extend it > just like this would do but for the convenience of the implementation it is > sometimes better to do a simple closure. > >> Defining a class properly is certainly still going to be the majority >> of uses of classes in PHP. That helps with the Optimizer, and helps >> code reuse. >> >> Sadly due to the way in which people have had ONE CLASS ONE FILE >> drilled into their head since PEAR and continuing through Zend and >> PSR-0, it can become a PITA to add some simple functionality if a >> small class is needed for one tiny thing. > > > I see the point here, but the argument to me seems void. Nothing wrong with > a simple class one file for a small class. >
Something doesn't have to be "wrong", another approach can just be more convenient, or handy for different use cases. One class one file can be rather slow depending on the autoloader setup, and depending on whether zend optimizer is enabled or not. For a distributed application running on mostly crap shared hosting, relying on Zend Optimizer is not an option, so the more of these little one-class one-file situations you have the worse it becomes. This RFC offers a solution for people that is not "Jam a bunch of these classes at the top of the current file" or "Make a whole load of one-time use classes to avoid that mess, plus people will snort and shame you for failing to follow decade old best practices." -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php