Hi Rasmus,

On 27 June 2016 at 20:37, Rasmus Schultz <ras...@mindplay.dk> wrote:

> Tonight I started trying to write a proposal for even more simplified
> annotations, e.g. something simple enough that it cannot result in
> fatal errors. I eventually gave up, and here's why.
>
> Essentially, if you have to restrict yourself to things that cannot
> under any circumstances error out, the only things you can use are
> constant scalar values - even constant scalar expressions could not be
> allowed, because even those could error when CONST_NAME or
> Class::CONST_NAME aren't defined.
>
> So, in a nutshell, what you're saying (Richard) is that annotations
> can only consist of scalar values, and possibly arrays of values? (and
> I don't even see your gist doing that - it's just invoking closures,
> as far as I can tell, and any of those could error, or not?)
>
> So, regardless of syntax, literally the only annotation data allowed
> would be blatantly simple things like:
>
>     ["max_length" => 20]
>
>     ["data_type" => "int"]
>
> Or in other words, constant arrays, int, string, float and bool
> values. Nothing else.
>
> Nothing can depend on any kind of external symbol (class names,
> constants, etc.) since any such reference can cause an error.
>
> No static analysis or type-checking of any kind can ever be performed
> - no assertions or declarations can be made about the shape or types
> of metadata, at all.
>
> The problem is, that's simply not useful.
>

That's actually what doctrine/annotations has been for a while  tho, and a
lot of people rely just on that.
The data-structure is still enforced by a VO-style class (the annotation
itself) in the library, though.

It would still be very useful, in my opinion.

Note that the existing annotation libs out there do indeed trigger
autoloading for referenced class constants.

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/

Reply via email to