Re: [RFC] PHP Attributes
| From: | Dmitry Stogov | Date: | Fri, 22 Apr 2016 11:13:34 +0000 |
| Subject: | Re: [RFC] PHP Attributes | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-92637@lists.php.net to get a copy of this message | ||
<<Entry>> works fine
sapi/cli/php attr6.php
array(1) {
["Entity"]=>
bool(true)
}
$ cat attr6.php
<?php
<<Entity>>
function foo() {}
$r = new ReflectionFunction("foo");
var_dump($r->getAttributes());
?>
[dmitry@tpl2 CGI-DEBUG]$ sapi/cli/php attr6.php
array(1) {
["Entity"]=>
bool(true)
}
<<ORM\Entity>> - doesn't work now, but I'll implement this and extend RFC on
next week.
Thanks. Dmitry.
________________________________
From: Dominic Grostate <codekestrel@googlemail.com>
Sent: Friday, April 22, 2016 11:31
To: Dmitry Stogov
Cc: PHP internals
Subject: Re: [PHP-DEV] [RFC] PHP Attributes
I'm having a crack at it now. Seeing if I can use it to plug a new Annotation driver for
Doctrine.
Couple of things I've found so far are:
<<Entity>> with empty args doesn't work.
<<ORM\Entity>> namespace doesn't work.
On the subject of using @, that could denote a class constructor, unless someone already mentioned
that.
On 22 Apr 2016 12:44 a.m., "Dmitry Stogov" <dmitry@zend.com<mailto:dmitry@zend.com>> wrote:
On 04/22/2016 02:16 AM, Dominic Grostate wrote:
This is amazing. It would actually allow us to implement our automated assertions ourselves, as
opposed to requiring it within the language.
this was the idea - to give a good tool instead of implementing every possible use-case in the
language.
Could it also support references?
<<sanitize(&$a)>>
function foo($a) {
}
yes. "&$a" is a valid PHP expression.
If you plan to use this, I would appreciate, if you to build the patched PHP and try it.
The early we find problems the better feature we will get at the end.
Thanks. Dmitry.
On 21 Apr 2016 10:13 p.m., "Dmitry Stogov" <dmitry@zend.com<mailto:dmitry@zend.com>> wrote:
Hi,
I would like to present an RFC proposing support for native annotation.
The naming, syntax and behavior are mostly influenced by HHVM Hack, but not exactly the same.
The most interesting difference is an ability to use arbitrary PHP expressions as attribute values.
These expressions are not evaluated, but stored as Abstract Syntax Trees, and later may be accessed
(node by node) in PHP extensions, preprocessors and PHP scripts their selves. I think this ability
may be useful for "Design By Contract", other formal verification systems, Aspect Oriented
Programming, etc
https://wiki.php.net/rfc/attributes
Note that this approach is going to be native, in contrast to doc-comment approach that uses not
well defined syntax, and even not parsed by PHP itself.
Additional ideas, endorsement and criticism are welcome.
Thanks. Dmitry.