On 23 September 2013 10:44, Sebastian Krebs <krebs....@gmail.com> wrote:

> 2013/9/23 Rasmus Lerdorf <ras...@lerdorf.com>
>
> > On 09/22/2013 11:39 PM, Joe Watkins wrote:
> > >     https://wiki.php.net/rfc/anonymous_classes
> > >
> > >     I'd like to hear thoughts regarding the addition of anonymous
> > > classes, patch included.
> >
> > I am having a hard time picturing a real-world use-case for this.
> >
>
> The use case is one-time usage of an "implementation", where you currently
> probably pass callbacks into a "Callback*"-class like
>
>     $x = new CallbackFoo(function() {
>         /* do something */
>     });
>
> vs.
>
>     $x = new Foo () {
>         public function doSometing()
>         {
>             /* do something */
>         }
>     });
>
> Imagine you have several abstract methods in one interface/class, which
> would need several callbacks passed to the constructor.
> Also '$this' is mapped to the right objects.
>
> Regards,
> Sebastian
>
>
It also avoids usage of these classes outside the scope where they are
defined...

I'm not sure that I like it yet, since the only use cases so far are very
weird edge cases in my strange experiments.

Surely needs stronger use cases first...

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/

Reply via email to