rfc:annotations_v2
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:annotations_v2 [2019/02/05 22:30] – created draft version brzuchal | rfc: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 |
* Version: 0.1 | * Version: 0.1 | ||
* Date: 2019-02-05 | * Date: 2019-02-05 | ||
Line 54: | Line 54: | ||
</ | </ | ||
- | ==== 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: | ||
- | * '' | + | |
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * '' | + | * '' |
=== @Repeatable === | === @Repeatable === | ||
Line 101: | Line 115: | ||
$classAnnotations = $refl-> | $classAnnotations = $refl-> | ||
</ | </ | ||
- | |||
- | ===== 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=" | + | |
- | myArrayProperty=[1, | + | |
- | myEmbeded=@MyEmbededAnnotation() | + | |
- | ) | + | |
- | class Foo { | + | |
- | @MyPropertyAnnotation | + | |
- | private $property; | + | |
- | + | ||
- | @MyMethodAnnotation(" | + | |
- | public function bar() {} | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | Declaring custom annotations | + | |
<code php> | <code php> | ||
Line 156: | Line 153: | ||
$this-> | $this-> | ||
} | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Using annotations | ||
+ | |||
+ | <code php> | ||
+ | use Example\MyAnnotation; | ||
+ | use Example\MyEmbededAnnotation; | ||
+ | |||
+ | @MyAnnotation( | ||
+ | myProperty=" | ||
+ | myArrayProperty=[1, | ||
+ | myEmbeded=@MyEmbededAnnotation() | ||
+ | ) | ||
+ | class Foo { | ||
+ | @MyPropertyAnnotation | ||
+ | private $property; | ||
+ | | ||
+ | @MyMethodAnnotation(" | ||
+ | public function bar() {} | ||
} | } | ||
</ | </ |
rfc/annotations_v2.txt · Last modified: 2020/07/22 08:44 by brzuchal