rfc:lexical-anon

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:lexical-anon [2016/04/19 13:33] krakjoerfc:lexical-anon [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== PHP RFC: Lexical Scope Support for Anonymous Classes ====== ====== PHP RFC: Lexical Scope Support for Anonymous Classes ======
-  * Version: 0.1+  * Version: 0.2
   * Date: 2016-04-19   * Date: 2016-04-19
   * Author: krakjoe   * Author: krakjoe
Line 78: Line 78:
  
 It has been suggested that it would be better to have [use(...)] on each function declaration. This would lead to a lot of repetition, and fragmented code that is more difficult to reason about. It has been suggested that it would be better to have [use(...)] on each function declaration. This would lead to a lot of repetition, and fragmented code that is more difficult to reason about.
 +
 +Another suggestion made is to allow symbols inline, so that the following code is legal:
 +
 +<code php>
 +class {
 +    public $prop = $var;
 +}
 +</code>
 +
 +This has some appealing advantages, such as using expression to initialize properties. But it also raises huge inconsistencies, why should this:
 +
 +<code php>
 +class {
 +    public $prop = new Foo();
 +}
 +</code>
 +
 +Be allowed, while not allowing the same thing in normal classes.
 +
 +Additionally, the following code would also have to be legal:
 +
 +<code php>
 +class {
 +    public $prop = &$this->prop;
 +}
 +</code>
 +
 +This is almost literally backwards.
 +
 +If we are going to allow expressions for anonymous classes that we do not allow for normal classes, then it is better to leave that for another RFC.
 +
 +What we are doing is only importing symbols, we don't //need// to invent a new way to initialize them.
  
 The cognitive overhead of "anything use'd by the declaration is a member property" is almost nil. The cognitive overhead of "anything use'd by the declaration is a member property" is almost nil.
Line 90: Line 122:
 The property reference must be well formed, and accessible in the lexical scope: The property reference must be well formed, and accessible in the lexical scope:
  
-''$object->property''+<code php> 
 +$object->property 
 +</code> 
 + 
 +A property name cannot be used twice: 
 + 
 +<code php>use($prop, $prop)</code> 
 + 
 +and 
 + 
 +<code php>use($prop, $this->prop)</code> 
 + 
 +Will both raise compile time errors: 
 + 
 +<code> 
 +Fatal error: Cannot use property name glow twice in /in/file on line 6 
 +</code>
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
Line 113: Line 161:
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
-https://github.com/php/php-src/compare/master...krakjoe:lexical-anon+https://github.com/php/php-src/pull/1874
  
 ===== Implementation ===== ===== Implementation =====
rfc/lexical-anon.1461072818.txt.gz · Last modified: 2017/09/22 13:28 (external edit)