Re: [RFC] PHP Attributes
| From: | Dmitry Stogov | Date: | Fri, 22 Apr 2016 07:17:42 +0000 |
| Subject: | Re: [RFC] PHP Attributes | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-92630@lists.php.net to get a copy of this message | ||
On 04/22/2016 05:15 AM, Sara Golemon wrote:
On Thu, Apr 21, 2016 at 2:13 PM, Dmitry Stogov <dmitry@zend.com> wrote:Good point. It's really not a big deal to run ast\parse_code($r->getAttributes()["foo"]) This would simplify the implementation a bit.I would like to present an RFC proposing support for native annotation.I'm trying to imagine where the benefit of non-constant expressions comes in. <<foo($a < 1)>> Assuming we roll in php-ast at the same time (which is a big addition, IMO, and deserves its own separate RFC), what are users meant to do with this? Even if there's a use-case here, one could accomplish the same thing with: <<foo('$a < 1')>> And manually running that string into php-ast if that's what the caller wanted.
Also, maybe I missed it, but I didn't see an answer to the question of ambiguity between parsing the above as a straight string, versus parsing it as a ZEND_AST_ZVAL. I'm sure the answer is "If the AST tree is just a ZVAL, then it's provided as the compile-time expression, but what about something else like this: <<foo(1+1)>> Logically, this is reducible to a single compile-time value, but it's a complex expression, so would it be the value int(2)? Or ZEND_AST_BINARY_OP(int(1), int(1))? Currently this going to be an AST - ZEND_AST_BINARY_OP(int(1), int(1))
I just think that over-engineers what should be a simple annotation feature.This makes sense. I think, I'll follow your suggestion. The only missing ability is syntax check for <expression> attribute values.
All that said, I love the proposal overall, and I can't wait to propose builtin annotations like <<__Memoize>>, <<__Mock>>, and similar. I'm looking forward as well. :)Thanks. Dmitry.
-Sara