On 05/13/2016 02:57 PM, Davey Shafik wrote:
> On Fri, May 13, 2016 at 2:11 PM, Rasmus Schultz <ras...@mindplay.dk> wrote:
>
>> Dear Internals,
>>
>> I'm announcing a simplified RFC for annotations:
>>
>> https://wiki.php.net/rfc/simple-annotations
>>
>> It's an alternative to the proposed Attributes RFC and the (2010)
>> Annotations RFC.
>>
>> I'm attempting with this to describe a feature that is closer to the
>> language than what is proposed by the Attributes RFC, by permitting
>> the use of any valid PHP expression as an annotation value.
>>
>> Where the Attributes RFC proposes new syntax for what is essentially
>> arrays, this proposal instead permits you to use actual arrays, e.g.
>> without inventing any new syntax. It also allows you to use values of
>> any other type, including objects. This makes the proposed feature
>> more immediately useful, with a minimal learning curve.
>>
>> Compared with the old Annotations RFC (and Doctrine Annotations, etc.)
>> this proposal does not attempt to define or enforce any rules about
>> what annotations are, permitted usage, inheritance rules, etc. -
>> instead it adds a very simple language feature upon which the
>> community may choose to build (and evolve) facilities that implement
>> additional rules and logic.
>>
>> My hope is that, if we can agree on something very small and simple,
>> we can defer the more opinionated discussions about rules and logic to
>> the community.
>>
>> In my opinion, language features should be simple, and consistent with
>> the language - I believe the way to do that, is to avoid discussions
>> about how such as facility should be used, and instead focus on how it
>> should work. There is a lot of opinion built into the old Annotations
>> RFC, and into Doctrine - features that attempt to dictate how the
>> feature should be used. I don't believe the language should dictate
>> what is or isn't correct or appropriate use.
>
> I think I like this, however a couple of simple questions:
>
> 1) Any chance for (optionally) _naming_ annotations? It would be nice to be
> able to do: ->getAnnotation('table') and not have to handle unnecessary
> annotations
not sure you need that, you can do this instead:
->getAnnotations(Table::class)
however it won't throw an error if you have more than one "Table::class
annotation" whereas I supposed you would expect so with a named annotation
>
> 2) I like the idea of Hacks memoize for example, how do you see those being
> implemented? Or don't you?
if Rasmus goal is to that "we can agree on something very small and
simple" I guess it would best be left for another rfc
>
> 3) When are annotations executed? On ->getAnnotations()? Every time?
given they are context free, I suppose they would be executed on the
first call only

but what about this kind of annotation classes? :

class Counter {
  private static $i = 0;
  private $n;
  function __construct() {
    $this->n = self::$i++;
  }
  function get() { return $this->n; }
}

both the getAnnotations() calls order and whether or not annotations are
executed every time would make a difference

>
> Thanks,
>

-- 
Mathieu Rochette

Reply via email to