Most of those changes are ideas taken from the php-annotations lib (see its wiki too) by Rasmus Schultz.
I am not the author of that lib but have been discussing with him for a while and I am convinced that this could benefit Symfony users and PHP as a whole on the long run, if we standardized the annotations a bit more than what we have right now.
For example, you have to define the data type with @ORM\Column
, @var
and @Assert\Type()
. This is absurd, if we had a proper standard way of parsing type information, and all libraries used it, it would only require one annotation. It would also save much work on the library side since they don't have to each define their own way of parsing type information, with the inevitable gaps and inconsistencies that this introduces.
- Annotations without namespace prefix:
- There would be a set of standardized "autoimported" annotations (to be defined, but you can look at sample ones), e.g.
@var
,@param
, ... - If they don't exist, and are not specifically autoimported or ignored, an Exception is thrown.
- There would be a set of standardized "autoimported" annotations (to be defined, but you can look at sample ones), e.g.
- Annotations with namespace prefix (NO CHANGE):
- The prefix is resolved using
use
statements. - If the resulting class name does not exist, an Exception is thrown.
- The prefix is resolved using
- Syntax is more PHP-like, if you use
@foo()
whatever sits inside the parenthesis is basically what could fit inside a phparray()
. The syntax is equivalent to php arrays, and anything that can go in there (php constants,new Foo()
) is valid. - Parsing of "old-style" phpdocs like
@var SomeType
is delegated to the annotation class itself, so the annotation can parse that how it wants. Maybe this custom parsing could be possible for()
too, allowing us to support the current syntax for a transitional period, but I don't think it's a particularly good idea. - Nesting of annotations is not possible anymore, since this is not a valid php structure, but it seems that it's not really necessary to have nesting if we allow multiple annotations of the same name, and if you can instantiate any object to pass it to an annotation using
new Foo
, which seems to be the only case left in Doctrine.
- Multiple annotations of the same name are supported, optionally, the annotation defines that in its @usage annotation.
- Rules for inheritance are described towards the end of that page and they seem good so I'm not gonna repeat everything.
Now don't forget RFC means Request For Comments, please comment away, but don't flame. It might hurt some feelings of Annotation library developers, but please think of the users.
I disagree about saying that
@var
and@ORM\Column
does the same thing. The first one tells you what is the type of the object and nothing more. The Doctrine annotation controls the way it is persisted. So it needs many attributes to control it (optionnal but useful) and the same PHP object could be persisted in different ways (seedate
anddatetime
forDateTime
objects).And for nesting annotations, what about the way indexes are defined currently in Doctrine, by placing an array of indexes as one attribute of
@ORM\Table
?And I disagree about saying it is invalid in PHP. You can nest arrays and use objects as values of an array.