Re: [RFC] Simple Annotations
| From: | Rowan Collins | Date: | Tue, 28 Jun 2016 21:20:00 +0000 |
| Subject: | Re: [RFC] Simple Annotations | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-94316@lists.php.net to get a copy of this message | ||
On 28 June 2016 20:10:15 GMT+01:00, Pedro Cordeiro <pedronaroga@gmail.com> wrote:
>> << HttpMethod::post() >> // equivalent to static method-call
>> HttpMethod::post()
>>
>
>What would this, specifically, do? Would it call HttpMethod::post()
>when
>the class gets instantiated and return its return on a
>ReflectionClass::getAnnotations()? Why is it necessary to be able to
>evaluate expressions on annotations?
I'm not sure if it's definitely necessary, but the stated use case was for factories /
named constructors. PHP only has one constructor per class, so it's not uncommon to have static
createFromX methods.
Since this will eventually evaluate as "new Foo(42)":
<< Foo(42) >>
The idea is that this would be available to call a factory instead:
<< Foo::fromRoman('XLII') >>
The neat thing being that by limiting the options to this, you can still extract a class name for
every annotation.
I say "eventually", because as proposed, this won't actually happen until you
explicitly ask for the "instance" of the annotation. See previous examples.
Regards,
--
Rowan Collins
[IMSoP]