rfc:closures:object-extension
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:closures:object-extension [2010/08/11 13:25] – bindTo changes cataphract | rfc:closures:object-extension [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Closures: Object extension ====== | ====== Closures: Object extension ====== | ||
+ | * Date: 2009-01-22 | ||
+ | * Author: Unknown | ||
+ | * Status: Implemented in PHP 5.4 | ||
+ | |||
+ | ===== Introduction ===== | ||
Efforts were made to go beyond the scope of the original Closures proposal ([[rfc/ | Efforts were made to go beyond the scope of the original Closures proposal ([[rfc/ | ||
Line 399: | Line 404: | ||
==== Private/ | ==== Private/ | ||
- | The currently implemented handling of scope for class closures is | + | The currently implemented handling of scope for class closures is: |
- | - They initially inherit the (calling) scope of the class they were created in. | + | |
- | - After that, always use the class scope of the object that bindTo() is called for ([[# | + | - After that, always use the class scope of the object that bindTo() is called for ([[# |
- | - If there' | + | - If there' |
The implementation of option #2 has serious drawbacks. Consider the following code: | The implementation of option #2 has serious drawbacks. Consider the following code: | ||
Line 430: | Line 435: | ||
There' | There' | ||
- | Therefore, I propose an implementation ([[http:// | + | Therefore, I propose an implementation ([[http:// |
< | < | ||
Line 439: | Line 444: | ||
The patch preserves these invariants: | The patch preserves these invariants: | ||
- | - A static closure, being scoped or not, cannot have any bound instance. | + | |
- | - A non static closure has a bound instance iif it is scoped. | + | - A non static closure has a bound instance iif it is scoped. |
To preserve these invariants, there are these additional rules: | To preserve these invariants, there are these additional rules: | ||
- | - If a non static closure is given a scope (or it already has a scope, but the scope parameter is not specified) and a NULL instance, it's made static. | + | |
- | - If a static closure is given an instance, the instance is ignored and an '' | + | - If a static closure is given an instance, the instance is ignored and an '' |
- | - If a non static non scoped (and therefore non bound) instance is given no scope and a non NULL instance, it's given a dummy scope (currently the " | + | - If a non static non scoped (and therefore non bound) instance is given no scope and a non NULL instance, it's given a dummy scope (currently the " |
Example: | Example: |
rfc/closures/object-extension.1281533155.txt.gz · Last modified: 2017/09/22 13:28 (external edit)