rfc:attribute_amendments

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
rfc:attribute_amendments [2020/06/04 09:00] – Go away from Attributes namespace beberleirfc:attribute_amendments [2020/06/04 21:26] beberlei
Line 1: Line 1:
 ====== PHP RFC: Attribute Amendments ====== ====== PHP RFC: Attribute Amendments ======
  
-  * Version: 1.0+  * Version: 1.2
   * Date: 2020-05-11   * Date: 2020-05-11
   * Author: Benjamin Eberlei (beberlei@php.net), Martin Schröder   * Author: Benjamin Eberlei (beberlei@php.net), Martin Schröder
Line 70: Line 70:
 </code> </code>
  
 +This feature would be superseded by any other RFC getting accepted that changes the syntax.
  
 ===== Validate Attribute Target Declarations ===== ===== Validate Attribute Target Declarations =====
Line 127: Line 128:
     public const int TARGET_ALL = ((1 << 6) - 1);     public const int TARGET_ALL = ((1 << 6) - 1);
  
-    public function __construct(int $target = self::TARGET_ALL)+    public function __construct(int $flags = self::TARGET_ALL)
     {     {
     }     }
Line 144: Line 145:
  
 For this reason we propose that by default attributes are not repeatable, and only For this reason we propose that by default attributes are not repeatable, and only
-if the attribute has the //RepeatableAttribute// attribute in addition to //PhpAttribute//+if the //PhpAttribute// has the flag //IS_REPEATABLE//
 should it be possible to use it multiple times on the same declaration: should it be possible to use it multiple times on the same declaration:
  
 <code php> <code php>
-<<PhpAttribute, RepeatableAttribute>>+class PhpAttribute 
 +
 +    public const int IS_REPEATABLE = ((1 << 10)); 
 +
 + 
 +<<PhpAttribute(self::IS_REPEATABLE)>>
 class Route class Route
 { {
Line 163: Line 169:
 </code> </code>
  
-An alternative approach would be to introduce a second argument to //PhpAttribute// for flags: +Important note: The repeatable flag of an attribute is validated during the call to //ReflectionAttribute::newInstance//.
- +
-<code php> +
-<<PhpAttribute(PhpAttribute::TARGET_ALL, PhpAttribute::IS_REPEATABLE)>> +
-class Route +
-+
-+
- +
-// with named parameters: +
-<<PhpAttribute(flags: PhpAttribute::IS_REPEATABLE)>> +
-class Route +
-+
-+
-</code> +
- +
-Important note: The repeatable definition of an attribute is validated during the call to //ReflectionAttribute::newInstance//.+
 In fact it does not influence a call to //Reflection*::getAttributes()// and //ReflectionAttribute// instances can be returned In fact it does not influence a call to //Reflection*::getAttributes()// and //ReflectionAttribute// instances can be returned
 from this method, that are not valid on the reflected declaration. This is in line with the deferred validation of userland attributes from this method, that are not valid on the reflected declaration. This is in line with the deferred validation of userland attributes
Line 185: Line 176:
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
  
-No breaks.+Introducing a class //Attribute// into the global namespace is certainly going to break at least a handful of applications using this class name
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
Line 207: Line 198:
 ===== Open Issues ===== ===== Open Issues =====
  
-  - For repeated attribute declaration: Use a dedicated attribute class or flags on //PhpAttribute//? +none
  
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
Line 225: Line 215:
  
   - [[https://wiki.php.net/rfc/attributes_v2|Attributes RFC]]   - [[https://wiki.php.net/rfc/attributes_v2|Attributes RFC]]
 +  
 +===== Updates =====
 +
 +  - 1.0 Initial RFC (11.5.2020)
 +  - 1.1 Attributes\Attribute namespace (28.5.2020)
 +  - 1.2 Revert Attributes\Attribute namespace, make IS_REPEATABLE flag on PhpAttribute (4.6.2020)
  
rfc/attribute_amendments.txt · Last modified: 2020/06/29 09:07 by beberlei