On Sat, Apr 30, 2016 at 9:47 AM, Larry Garfield <la...@garfieldtech.com> wrote:
> 3) Some way to provide a data definition for the annotation that can be > checked at compile time. This could be classes, a la Doctrine. It could be > a new Annotation type as others have suggested. It could be something > else, akin to a struct like Liz Smith keeps toying with. I'm flexible > here. But some way to provide a data definition for the annotation that is > more robust than "you get an AST for an associative array that you can eval > to an array yourself, good luck" is, I believe, mandatory for these to be > successful for more than the most trivial use cases. If that data > definition is a class or class-like type, that also resolves the namespace > question very easily. > > I would love it if annotations were just classes with public properties, and the annotation shorthand for instantiating and setting properties was generally avaliable. At the moment if you wish to instantiate an object and set some public properties, you have to use a temporary variable $album = new Album(); $album->name = "Albumius"; $album->artist = "Artistus"; $album->year = 2013; return $album; or define setters for all the properties so you can chain them return (new Album()) ->setName("Albumius") ->setArtist("Artistus") ->setYear(2013); or forego the benefits of classes and use an array return [ 'name' => "Albumius", 'artist' => "Artistus", 'year' => 2013, ]; C# has an "instantiate-and-set-properties" shorthand like this, which would be great to have in PHP: return new Album() { name = "Albumius", artist = "Artistus", year = 2013, }; and if you drop the "new" (and constructor parens are already optional) you've got a pretty good annotation syntax right there. <<Links { canonical = "/node/{node}", deleteForm" = "/node/{node}/delete", editForm" = "/node/{node}/edit", versionHistory" = "/node/{node}/revisions", revision" = "/node/{node}/revisions/{node_revision}/view", }>> <<Foo("param", "param")>> <<Blah(5) { foo = 5 }>> So the annotation syntax could just be class instantiation without the "new". (maybe there should be a $ before the property names, not sure)