-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Implement PHP attributes #1878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement PHP attributes #1878
Conversation
Umm what is this one? PHP native support for annotation? |
Yes, but it's incomplete yet. On Wed, Apr 20, 2016 at 4:16 PM -0700, "HallofFamer" <notifications@github.commailto:notifications@github.com> wrote: Umm what is this one? PHP native support for annotation? You are receiving this because you authored the thread. |
* master: Fixed bug #72059 - Reference the bug id directly in NEWS Fix magic constants (__LINE__) with ?? for constant scalar exprs Add NEWS entry for ?? in constant scalar expressions allow null coalescing (??) on constant expressions
I see, so you decide to call it 'attributes', interesting. And the syntax for annotations is <>? How about just ? I doubt angle brackets are used in any existing PHP language construct yet. |
I took syntax from HHVM: https://docs.hhvm.com/hack/attributes/introduction From: HallofFamer notifications@github.com I see, so you decide to call it 'attributes', interesting. And the syntax for annotations is <>? How about just ? I doubt angle brackets are used in any existing PHP language construct yet. You are receiving this because you authored the thread. |
* master: Added news entry Safe execution timeout handling.
* master: Take pi defs into account when propagating defs Make pi placement independent of phi placement Drop some unnecessary checks Introduce ZEND_BITSET_FOREACH macros Fixed bug #68658 (Define CURLE_SSL_CACERT_BADFILE) Fix cURL test to use local server instead of google Fixed bug #72035 php-cgi.exe fails to run scripts relative to drive root Fixed bug #72069 (Behavior \JsonSerializable different from json_encode) Fixed bug #72075 (Referencing socket resources breaks stream_select) Make zval_ptr_dtor / _zval_dtor_func more robust Adjust DFG allocation size Make MAY_BE_ERROR handling more accurate Fix escape sequences in pgsql.c Mark zend_timeout as noreturn Merge def and gen sets Fix constant expr coaleasce with protected mode opcache
* master: Skip test on ZTS build Fixed bug #72101 (crash on complex code) Fixed race conditions in test
- changed Reflection*::getAttributes() to always return arrays (empty array for entity without attributes) - changed Reflection*::getAttributes() to always return arrays for attribute values (empty array for attributes without value, array with single element for attributes with single value, etc) - disabled attribute names started with "__" prefix (they are reserved for special purpose)
https://wiki.php.net/rfc/attributes Despite of the fact the idea is borrowed from the hack, I'd personally (as a developer) prefer current annotation system over this implementation. The reason are:
Is generated by the previous one.
Also generated by the first one. The problem is that in the moments you want to have two attributes, The RFC advice is to replace the content with array. The structural problem strongly prohibit this behavior as you should check all possible argument formats every time you work with this attributes. Implementing these feature gives us a simple but really powerfull feature - backward compatibility with the previous annotation format. What's left - is a matter of format, which could be converted automatically using current software readers and AST implementation |
All these problem are solvable by higher layer (like it shown in "Doctrive" example). This RFC proposes just a base functionality in PHP core by design. |
Hack's developers offered very strange syntax for annotations. It looks like they did it because of that '@' is used to mute errors on functions. But I think this RFC should be based on bests existing implementations like Java's or maybe Python's. Moreover some very useful tools like Doctrine use Java-like syntax for years. For example:
Looks much better and more acquainted for new developers than this:
One more strange thing in Hack is "short" syntax for closures:
It is not that short actually... |
@dstogov The "Doctrine" example only show that all these problems should be solved in almost every attribute processor which allow multiple attributes extended by users. The solution is to implement software attribute parser which takes FQCN from the attribute name (I'm not sure,but current examples show that it ignores use directives, so you should write fqcn each time you want to reference a class), takes the positional arguments from the attribute and tries to instantiate an attribute class there. The question - where is the general difference with caching Doctrine Annotation Reader? Annotations are cached, so it reads them very quick, annotations are structured, multivalued. etc. |
I'm tired to repeat - "Doctrine" is not the only use case for attributes, and I'm not going to reimplement Doctrine in C. This RFC provides base functionality for native attribute parsing and storage. Then it may be re-used for extensible passer, design by contract, verification, attribute system, flags for PHP compiler, etc. |
Doctrine is NOT the USE case. doctrine\annotations is the implementation of annotation mechanism. It's already used in hundreds of software projects, uncluding symfony, zend framework, drupal. https://www.versioneye.com/php/doctrine:annotations/references (it's the list of the projects, using this directly, and many others use it transitionally). Making the proposed attributes implementation backward compatible with this mechanism:
|
* master: (146 commits) update NEWS update NEWS Revert "Fixed bug #71820 pg_fetch_object bind parameters before call constructor" Revert "Backport patch for bug #71820" Fixed bug #64524 Add intl.use_exceptions to php.ini-* Remove unnecessary strlen check Fixed test Fix include_once in phpdbg Strlen cleanup (additions for previous one fix) Fixed bug #72172 (zend_hex_strtod should not use strlen) Revert "Fixed bug #72170 (JsonSerializable may inc apply count without dec it)" Fixed bug #72170 (JsonSerializable may inc apply count without dec it) Add $http_response_header tests Fixed possible crash Reimplemented Bob's commit bac6fdb without insignificant renaming and white-space changes Fixed typo Revert "Refactor zval cleanup into single function" update NEWS reorder entry alphabetically Re-fix #72165 ...
Why can't we just have (something like) Java annotations in PHP? 😢 |
Closing as https://wiki.php.net/rfc/attributes has been declined, at least for now. |
No description provided.