Re: [RFC] Anonymous Classes
| From: | Philip Sturgeon | Date: | Mon, 09 Mar 2015 19:22:14 +0000 |
| Subject: | Re: [RFC] Anonymous Classes | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-84483@lists.php.net to get a copy of this message | ||
Matthew,
On Sun, Mar 8, 2015 at 11:04 PM, Matthew Leverton <leverton@gmail.com> wrote:
>>> $foo = class extends Callback { ... }
>>> $bar = new $foo;
>>
>> Nope, none of that. Wrap that in a function or clone it perhaps.
>>
> Are you actively against that functionality? (I don't think it's very
> useful, but was wondering if you think it's a bad idea for some
> reason.)
>
> I'm not sure what people think it should return. The name of the
> anonymous class??
>
> e.g., similar to:
>
> class Foo { }
> $foo = 'Foo';
> $fooInstance = new $foo;
>
> That seems odd to me. It could just return a ReflectionClass object:
>
> $reflector = class { public function bar() { } };
> $foo = $reflector->newInstance();
> $foo->bar();
>
> But I don't know if that would feel out of place. Otherwise, it seems
> like it would need to return some sort of "Class" object that could be
> typecasted, etc ... but in some ways that's what a ReflectionClass
> already is.
>
> Just throwing that out there.
>
> Big +1 on the RFC as presented.
>
> --
> Matthew Leverton
Thanks for the example! I would say: Yes, I am actively against that stuff.
Firstly, at this time no part of PHP that I know of will smash a
reflection object at you unless you specifically interact with the
reflection API and ask for it. That in itself is a major nope.
Secondly, it am unsure of the uses. you can wrap that in a function or
shove it in a named class if you need to create multiple instances of
it. Or, as I said, there is clone.
If usage of this simple feature starts to show that people feel
constrained by not having this extra feature, then I would say we
should add that later. I am a big fan of keeping it simple and
introducing things as people need them, instead of trying to cover all
future use cases. :)