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.


>
> Anonymous functions alleviate that annoyance with a simple and
> consistent feature that just give people a nice simple option to get
> their jobs done, without hitting autoloaders and file systems to do
> it.

Reply via email to