Re: RFC: Anonymous Classes

From: Date: Mon, 23 Sep 2013 08:44:47 +0000
Subject: Re: RFC: Anonymous Classes
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
2013/9/23 Rasmus Lerdorf <[email protected]>

> 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


>
> -Rasmus
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
github.com/KingCrunch


Thread (55 messages)

« previous php.internals (#69261) next »