Re: Annotations in PHP7

From: Date: Mon, 16 Feb 2015 21:02:36 +0000
Subject: Re: Annotations in PHP7
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-82888@lists.php.net to get a copy of this message
On Mon, Feb 16, 2015 at 11:05 PM, Benjamin Eberlei <kontakt@beberlei.de> wrote: > > > On Mon, Feb 16, 2015 at 12:07 PM, Dmitry Stogov <dmitry@zend.com> wrote: > >> hi, >> >> During discussion of different ways of implementing "Design by Contract" >> we >> got an idea of using annotations. >> >> BTW: annotations are useful by their own and may be used for different >> purposes. Support for annotations was proposed long time ago: >> >> https://wiki.php.net/rfc/annotations >> https://wiki.php.net/rfc/annotations-in-docblock >> https://wiki.php.net/rfc/reflection_doccomment_annotations >> >> HHVM already implemented similar concept >> >> http://docs.hhvm.com/manual/en/hack.attributes.php >> >> I made a quick and dirty PoC that shows how we may implement annotations >> in >> PHP7 and how powerful they may be : >> https://gist.github.com/dstogov/dbf2a8f46e43719bd2c2 > > > How about not exposing the AST, and then the userland can pass context to > a method $reflection->getAnnotation($name, $context); > > https://gist.github.com/beberlei/0dc36d4412b8e3454912 > > That way AST is not exposed to userland. > Your example handles just particular use-case. I would like to provide a general solution. Thanks. Dmitry. > >> >> The test there is self explainable. Of course, annotations just provide a >> way to add metadata, but doesn't define attribute names or the ways they >> are going to be used. Only Reflection API to read. >> >> There are still a lot of technical problems that have to be solved. >> Right now, we just need to answer a question - if we like this in PHP7? >> Thought and opinions are welcome... >> >> Thanks. Dmitry. >> > >

« previous php.internals (#82888) next »