RE: [PHP-DEV] Annotations in PHP7

From: Date: Wed, 18 Feb 2015 11:52:29 +0000
Subject: RE: [PHP-DEV] Annotations in PHP7
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.internals 
Request: Send a blank email to internals+get-83050@lists.php.net to get a copy of this message
Hi Dmitry, > De : Dmitry Stogov [mailto:dmitry@zend.com] > Nested annotations are not going to be necessary, because they may be > represented by PHP pseudo-syntax (and/or PHP array syntax) > > <Doctrine_Join( > ManyToMany($targetEntity="Phonenumber"), > JoinTable($name="users_phonenumbers", > $joinColumns=JoinColumn($name="user_id", > $referencedColumnName="id")) > inverseJoinColumns=JoinColumn($name="phonenumber_id", > $referencedColumnName="id", $unique=true))> > class User { > ... > } > > $r = new ReflectionClass("User"); > $ast = $r->getAnnotation("Doctine_Join"); > echo $ast->child[0]->child[0]; // "ManyToMany" > echo $ast->child[0]->child[1]->child[0]->child[0]; // "$targetEntity" > > or If we provide API similar to SimpleXML > > echo $ast[0][0]; // "ManyToMany" > echo $ast[0][1][0][0]; // "$targetEntity" Please, no new pseudo language. Either value is a bare string and application has responsibility to parse it, or it is a PHP expression, especially since we have short array syntax. If user needs runtime evaluation, as in DbC, he just passes his expression in a string. Accessing ast elements by index is quite poor too, and if it is to define associative pseudo-arrays, let's use PHP arrays. Also, a detail, same as Derick's : '<>' reminds html/xml too much, IMO. While completely different, it will confuse a lot of people. I prefer '<<>>'. No ambiguity. So : <<Doctrine_Join([ 'ManyToMany' => [ 'targetEntity' => "Phonenumber" ], 'JoinTable' => [ 'name' => "users_phonenumbers" , 'joinColumns' => [ [ 'name' => 'user_id', 'referencedColumnName' => 'id' ] ], 'inverseJoinColumns' => [ [ 'name' => "phonenumber_id", 'referencedColumnName' => "id", 'unique' => true ] ] ] ] ) >> A last question: in such a case, should '<<' strings appearing in the expression have to be quoted, or would it take care of string delimiters when searching for the end of the annotation ? Regards François

« previous php.internals (#83050) next »