Re: RFC: Anonymous Classes
| From: | Marco Pivetta | Date: | Mon, 23 Sep 2013 08:48:20 +0000 |
| Subject: | Re: RFC: Anonymous Classes | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-69262@lists.php.net to get a copy of this message | ||
On 23 September 2013 10:44, Sebastian Krebs <krebs.seb@gmail.com> wrote:
> 2013/9/23 Rasmus Lerdorf <rasmus@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/