This is an old revision of the document!
PHP RFC: Simple Annotations
- Version: 0.1
- Date: 2016-05-13
- Author: Rasmus Schultz, rasmus@mindplay.dk
- Status: Draft
- First Published at: http://wiki.php.net/rfc/simple-annotations
Introduction
This RFC proposes the introduction of simple value annotations - arbitrary meta-data values applicable to classes and class members, obtainable via the reflection API.
As an alternative proposal to attributes, this proposal aims to fully leverage existing language features, in order to provide more flexibility, lessen the learning curve, and expose meta-data in a manner that is more immediately useful, without having to build any run-time facilities.
Compared with annotation systems such as Doctrine Annotations, this proposal does not attempt to define or enforce any domain rules - it does not define inheritance semantics, rules about applicable source-code elements, or any other rules; these can be defined and implemented by userland packages.
Proposal
The proposed syntax of a single annotation is extremely simple:
"<<" <php-expression> ">>"
Any valid PHP expression is a valid annotation.
Any number of annotations may be placed in front of any of the following applicable declarations:
class
,trait
andinterface
declarationsfunction
and property declarations in classes/traits/interfaces- function and method argument declarations
- anonymous
function
andclass
declarations (and their members)
For example:
class Table { public function __construct($name) { $this->name = $name; } }
Annotations are internally collected, for each annotated class or member, in a list which can be obtained via reflection.
Backward Incompatible Changes
None.
Proposed PHP Version(s)
Next PHP 7.x.
RFC Impact
To SAPIs
TODO
To Existing Extensions
TODO
To Opcache
TODO
Open Issues
Make sure there are no open issues when the vote starts!
Unaffected PHP Functionality
Annotations are a new feature - it does not affect any existing functionality.
Future Scope
TODO file-level annotations? others?
Proposed Voting Choices
TODO State whether this project requires a 2/3 or 50%+1 majority (see voting)
Patches and Tests
There is a draft with no available implementation at this time.
Implementation
TODO After the project is implemented, this section should contain
- the version(s) it was merged to
- a link to the git commit(s)
- a link to the PHP manual entry for the feature
References
Rejected Features
None.