> -----Ursprüngliche Nachricht----- > Von: Rowan Collins [mailto:rowan.coll...@gmail.com] > Gesendet: Mittwoch, 12. November 2014 17:21 > An: internals@lists.php.net > Betreff: Re: [PHP-DEV] Annotation PHP 7 > > Marco Pivetta wrote on 05/11/2014 14:02: > > For example, this alternative approach perfectly fits the current > > doctrine/annotations use-case: > > > > use Doctrine\ORM\Mapping\Entity; > > use Doctrine\ORM\Mapping\Table; > > use Doctrine\ORM\Mapping\Id; > > use Doctrine\ORM\Mapping\GeneratedValue; > > use Doctrine\ORM\Mapping\Column; > > > > [Entity::class => []] > > [Table::class => ['name' => 'foo_table']] class Foo { > > [Id::class => []] > > [GeneratedValue::class => [GeneratedValue::UUID]] > > [Column::class => ['name' => 'bar_column', 'type' => 'string']] > > private $bar; > > } > > > > I did nothing special here, just using plain old associative arrays > > and built-in `::class` pseudo-constants: this leaves space for > > libraries that do want to use annotations, but not the way > > doctrine/annotations does it (calling the constructor of an > > annotation), and the annotations themselves can still decide what to do > > with nested values. > > > > No autoloading is going on, no code execution, nothing: plain and > > simple arrays which may as well be used for phpdocumentor as well, if > > needed. > > One problem with using *just* array syntax, without any new keyword or > symbols, is that it is extremely close to being > existing valid syntax. > This may well cause problems in the parser, and would certainly be confusing > to users. > > Specifically, a class annotation might look like this: > > ['Blah\\Annotation\\Table' => ['name' => 'foo_table']] class Foo { } > > But add a single semi-colon, and you have valid PHP code > [http://3v4l.org/inkul]: > > ['Blah\\Annotation\\Table' => ['name' => 'foo_table']]; class Foo { } > > This works because an expression, by itself, is a valid statement, as long as > it's terminated with a semi-colon, and before > the "class" > keyword, you are just in global execution scope (a problem many other > languages don't have to worry about, because > statements can't exist outside blocks). > > The same reasoning rules out simple uses of @ as the prefix, because this is > also valid code [http://3v4l.org/TCBbC]: > > @Blah\Annotation\Table( ['name' => 'foo_table'] ); class Foo { } > > Amusingly, the @ suppresses the non-existent function error, making this look > almost like it "worked". > > Having a single semi-colon change an annotation into a silent statement seems > like an extremely bad idea. The "inside" of > an annotation can look like an array or constructor call, but we need > something distinct to introduce (or wrap) it, assuming > we want it positioned before the "class" keyword, as in other languages. > > Regards, > -- > Rowan Collins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: > http://www.php.net/unsub.php
We could use something like the following. The : after @ makes it unambiguous @:['Blah\\Annotation\\Table' => ['name' => 'foo_table']] class Foo{} or @:Blah\Annotation\Table( ['name' => 'foo_table'] ) class Foo { } Just as an idea -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php