rfc:simple-annotations

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rfc:simple-annotations [2016/05/13 11:15]
mindplay
rfc:simple-annotations [2017/09/22 13:28] (current)
Line 1: Line 1:
 ====== PHP RFC: Simple Annotations ====== ====== PHP RFC: Simple Annotations ======
  
-  * Version: 0.1+  * Version: 0.3
   * Date: 2016-05-13   * Date: 2016-05-13
   * Author: Rasmus Schultz, rasmus@mindplay.dk   * Author: Rasmus Schultz, rasmus@mindplay.dk
Line 83: Line 83:
 ==== Annotations are Context-free ==== ==== Annotations are Context-free ====
  
-By design, there is no access to variables in the parent class, file or global scope, no ''self'' or ''static'' or ''$this''.+By design, annotations expressions are evaluated individually in an empty scope - which means there is no access to variables in the parent class, file, local or global scope, e.g. no ''$this''''self'' or ''static''.
  
 Annotations work consistently regardless of which source element they are applied to, and may be evaluated without first creating an object instance. Annotations work consistently regardless of which source element they are applied to, and may be evaluated without first creating an object instance.
- 
-You can think of an annotation ''<< expression() >>'' as executing in an anonymous function scope, e.g.: 
- 
-    function () { return expression(); } 
  
 Annotations that do require context should explicitly ask for that context - for example, you could use an anonymous function, a ''callable'', or an anonymous class, to provide context via dependency injection. Annotations that do require context should explicitly ask for that context - for example, you could use an anonymous function, a ''callable'', or an anonymous class, to provide context via dependency injection.
Line 108: Line 104:
 The optional ''$filter'' argument, if given, filters the returned list of annotations as follows: The optional ''$filter'' argument, if given, filters the returned list of annotations as follows:
  
- * If one of ''string'', ''int'', ''float'', ''bool'' are given, filters annotations using ''is_*()'' +   * If one of ''string'', ''int'', ''float'', ''bool'' are given, filters annotations using ''is_int()'', ''is_string()'', etc. 
- * If a fully-qualified class-name is given, filters annotations using ''instanceof''+   * If a fully-qualified class-name is given, filters annotations using ''instanceof''
  
 If ''null'' is given (default) all annotations are returned. If ''null'' is given (default) all annotations are returned.
Line 145: Line 141:
 Annotations are a new feature - it does not affect any existing functionality. Annotations are a new feature - it does not affect any existing functionality.
  
-===== Future Scope =====+===== Out of Scope =====
  
-TODO file-level annotations? others?+It has been suggested that this RFC should reserve certain names for compiler directives, such as (for instance) the memoization-directive [[https://docs.hhvm.com/hack/attributes/special|supported by Hack]]. This proposal does not reserve any such names, because (as others pointed out during that discussion) these are not meta-data, but rather directives for the compiler, and such features ought to be supported directly by keywords or syntax rather than by magical meta-data.
  
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
rfc/simple-annotations.1463138155.txt.gz · Last modified: 2017/09/22 13:28 (external edit)