rfc:simple-annotations
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
rfc:simple-annotations [2016/05/13 09:35] – created mindplay | rfc:simple-annotations [2016/06/27 17:45] – remove provision about reserved annotations mindplay | ||
---|---|---|---|
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 9: | Line 9: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | This RFC proposes the introduction of simple value annotations - arbitrary | + | This RFC proposes the introduction of simple value annotations - arbitrary values |
As an alternative proposal to [[https:// | As an alternative proposal to [[https:// | ||
- | Compared with annotation systems such as [[https:// | + | Compared with annotation systems such as [[https:// |
===== Proposal ===== | ===== Proposal ===== | ||
- | The proposed syntax of a single annotation is extremely | + | The proposed syntax of a single annotation is very simple: |
< | < | ||
Line 29: | Line 29: | ||
* '' | * '' | ||
* '' | * '' | ||
- | * function | + | * anonymous '' |
- | * anonymous | + | * anonymous '' |
+ | * argument declarations of functions, methods and closures | ||
- | For example: | + | Annotations are internally collected, for each annotated class or member, in a list which can be obtained via reflection. |
+ | |||
+ | The following trivial | ||
<code php> | <code php> | ||
- | class Table | + | << "Hello World" >> |
- | { | + | << [1, 2, 3] >> |
+ | class Hello | ||
+ | {} | ||
+ | </ | ||
+ | The following example annotates an entity with a '' | ||
+ | |||
+ | <code php> | ||
+ | class TableName | ||
+ | { | ||
+ | public $name; | ||
+ | | ||
public function __construct($name) { | public function __construct($name) { | ||
$this-> | $this-> | ||
} | } | ||
} | } | ||
+ | |||
+ | << new TableName(" | ||
+ | class User | ||
+ | { | ||
+ | // ... | ||
+ | } | ||
+ | |||
+ | $reflection = new ReflectionClass(User:: | ||
+ | |||
+ | var_dump($reflection-> | ||
</ | </ | ||
- | Annotations | + | Example output: |
+ | |||
+ | < | ||
+ | array(1) { | ||
+ | [0]=> | ||
+ | object(TableName)# | ||
+ | [" | ||
+ | string(5) " | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Annotation expressions | ||
+ | |||
+ | ==== Annotations are Context-free ==== | ||
+ | |||
+ | By design, annotations expressions are evaluated individually in an empty scope - which means there is no access to variables in the parent | ||
+ | |||
+ | Annotations work consistently regardless of which source element they are applied to, and may be evaluated without first creating an object instance. | ||
+ | |||
+ | Annotations that do require context should explicitly ask for that context - for example, you could use an anonymous function, a '' | ||
+ | |||
+ | ==== Reflection API ==== | ||
+ | |||
+ | The following classes will have an added '' | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | The '' | ||
+ | |||
+ | public function getAnnotations($filter = null) : array | ||
+ | |||
+ | The optional '' | ||
+ | |||
+ | * If one of '' | ||
+ | * If a fully-qualified class-name is given, filters annotations using '' | ||
+ | |||
+ | If '' | ||
+ | |||
+ | These methods do not take into account inheritance - annotations belong to the actual *declaration*, | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 76: | 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 | + | ===== Out of Scope ===== |
- | TODO file-level annotations? | + | It has been suggested that this RFC should reserve certain names for compiler directives, such as (for instance) the memoization-directive [[https:// |
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
Line 102: | Line 167: | ||
None. | None. | ||
- |
rfc/simple-annotations.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1