rfc:annotations_v2

Differences

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

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
rfc:annotations_v2 [2019/02/05 22:30] – created draft version brzuchalrfc:annotations_v2 [2019/02/05 22:59] – Distinguished between Meta-Annotations and Built-in Annotations brzuchal
Line 1: Line 1:
-====== PHP RFC: Annotations ======+====== PHP RFC: Annotations 2.0 ======
   * Version: 0.1   * Version: 0.1
   * Date: 2019-02-05   * Date: 2019-02-05
Line 54: Line 54:
 </code> </code>
  
-==== Built in annotations ====+==== Built-in annotations ==== 
 + 
 +First, there are several that inform compilation: 
 + 
 +=== @Compiled === 
 +Function scoped annotation indicating if a function should be JIT compiled. 
 + 
 +=== @SupressWarnings === 
 +Function or statement scoped annotation indicating if error supression should be applied. 
 + 
 +==== Meta-Annotations ==== 
 + 
 +Next, meta-annotations are annotations that can be applied to other annotations. 
 + 
 +For example, these meta-annotations are used for annotation configuration:
  
 === @Annotation === === @Annotation ===
Line 70: Line 84:
 Then you could define one or more targets: Then you could define one or more targets:
  
-* ''CLASS'' allowed before the class declaration +  * ''CLASS'' allowed before the class declaration 
-* ''PROPERTY'' allowed before class property declaration +  * ''PROPERTY'' allowed before class property declaration 
-* ''METHOD'' allowed before the class method declaration +  * ''METHOD'' allowed before the class method declaration 
-* ''FUNCTION'' allowed before the function declaration +  * ''FUNCTION'' allowed before the function declaration 
-* ''ALL'' allowed in all cases, also default value +  * ''ALL'' allowed in all cases, also default value 
-* ''ANNOTATION'' allowed before annotation class declaration+  * ''ANNOTATION'' allowed before annotation class declaration
  
 === @Repeatable === === @Repeatable ===
Line 101: Line 115:
 $classAnnotations = $refl->getAnnotations(); // will include @MyInheritedAnnotation only $classAnnotations = $refl->getAnnotations(); // will include @MyInheritedAnnotation only
 </code> </code>
- 
-===== Examples ===== 
  
 ==== Custom annotations ==== ==== Custom annotations ====
-Using annotations 
  
-<code php> +Annotation type declarations are similar to normal class declarations. 
-use Example\MyAnnotation; +Each property declaration defines an element of the annotation type. 
-use Example\MyEmbededAnnotation;+Property types are restricted to primitives or another annotation type.
  
-@MyAnnotation( +Declaring custom annotations:
-    myProperty="value",  +
-    myArrayProperty=[1, 3.14, true, "string", DIRECTORY_SEPARATOR],  +
-    myEmbeded=@MyEmbededAnnotation() +
-+
-class Foo { +
-    @MyPropertyAnnotation +
-    private $property; +
-   +
-    @MyMethodAnnotation("value"+
-    public function bar() {} +
-+
-</code> +
- +
-Declaring custom annotations+
  
 <code php> <code php>
Line 156: Line 153:
         $this->value = $value;         $this->value = $value;
     }     }
 +}
 +</code>
 +
 +Using annotations
 +
 +<code php>
 +use Example\MyAnnotation;
 +use Example\MyEmbededAnnotation;
 +
 +@MyAnnotation(
 +    myProperty="value", 
 +    myArrayProperty=[1, 3.14, true, "string", DIRECTORY_SEPARATOR], 
 +    myEmbeded=@MyEmbededAnnotation()
 +)
 +class Foo {
 +    @MyPropertyAnnotation
 +    private $property;
 +  
 +    @MyMethodAnnotation("value")
 +    public function bar() {}
 } }
 </code> </code>
rfc/annotations_v2.txt · Last modified: 2020/07/22 08:44 by brzuchal