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
Next revisionBoth sides next revision
rfc:lexical-anon [2016/04/19 13:16] krakjoerfc:lexical-anon [2016/04/20 06:44] krakjoe
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
-  * Status: Draft+  * Status: Under Discussion
   * First Published at: http://wiki.php.net/rfc/lexical-anon   * First Published at: http://wiki.php.net/rfc/lexical-anon
  
 ===== Introduction ===== ===== Introduction =====
-Anonymous classes are cumbersome to use because they lack support for lexical scope variables.+Anonymous classes are cumbersome to use because they lack support for lexical scope [use()].
  
 If the anonymous class has dependencies, they must be injected via the constructor, which is verbose, repetitive, and widens the margin for error considerably. If the anonymous class has dependencies, they must be injected via the constructor, which is verbose, repetitive, and widens the margin for error considerably.
Line 80: Line 80:
  
 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.
 +
 +===== Error Conditions =====
 +
 +The same restrictions that apply to use() on function declarations apply:
 +
 +  * Must not be superglobal name
 +  * Must not be ''$this''
 +
 +The property reference must be well formed, and accessible in the lexical scope:
 +
 +''$object->property''
 +
 +A property name cannot be used twice:
 +
 +''use($prop, $prop)''
 +
 +and
 +
 +''use($prop, $this->prop)''
 +
 +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 102: Line 127:
  
 ===== 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.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1