Re: [RFC] Anonymous Classes
| From: | Dmitry Stogov | Date: | Tue, 24 Feb 2015 14:34:33 +0000 |
| Subject: | Re: [RFC] Anonymous Classes | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-83667@lists.php.net to get a copy of this message | ||
On Tue, Feb 24, 2015 at 5:19 PM, Philip Sturgeon <pjsturgeon@gmail.com>
wrote:
> On Tue, Feb 24, 2015 at 9:10 AM, Dmitry Stogov <dmitry@zend.com> wrote:
> > I think the proposal is a bit incomplete.
> > It's possible to instantiate an anonymous class, but currently it's not
> > possible to do with them anything else (assign to variable, pass to
> > function, etc). Something similar to Closure objects should be
> introduced.
> >
> > Thanks. Dmitry.
>
> 1. You can absolutely assign the instantiated classes to variables.
>
> Check out this test in the patch:
>
>
> https://github.com/krakjoe/php-src/compare/anon#diff-25e330fb5a98810de178a5b798102d01R1
>
>
In tests you assign instantiated objects.
$a = new class {...};
$b = new class {...};
I'm talking about classes as first class objects.
$c = class {...};
$a = new $c;
$b = new $c;
> 2. Why do you say they cannot be passed to a function? I can add a
> test if you can give me an example of what you're suggesting doesn't
> work.
>
> 3. Not sure why we'd need a Closure-alike object. Anonymous classes
> are just a class, and classes have all the types and hinting
> functionality of regular classes. You don't need to implement a class
> to let people know its a class.
>
> Maybe you could expand on that a bit? :)
>
I tried it in the example above.
Also, classes may be useful without objects at all (just static properties
and methods).
$c = class {...};
$c::static_foo();
Thanks. Dmitry.