rfc:function_referencing

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:function_referencing [2014/08/03 14:58] ajfrfc:function_referencing [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== PHP RFC: Function Referencing as Closures ====== ====== PHP RFC: Function Referencing as Closures ======
   * Version: 0.1   * Version: 0.1
-  * Date: 2014-08-03+  * Date: 2014-08-03, latest 2014-08-18, withdrawn 2014-11-03
   * Author: Andrea Faulds, ajf@ajf.me   * Author: Andrea Faulds, ajf@ajf.me
-  * Status: Draft+  * Status: Withdrawn
   * First Published at: http://wiki.php.net/rfc/function_referencing   * First Published at: http://wiki.php.net/rfc/function_referencing
  
Line 43: Line 43:
 $qux = new FooBar(3); $qux = new FooBar(3);
  
 +// Static functions referenced retain their scope
 $func = &FooBar::getStatic; $func = &FooBar::getStatic;
 +// Thus it can see the instance variables of $qux
 $func($qux); // 3 $func($qux); // 3
  
 $func = &FooBar::get; $func = &FooBar::get;
 $func->call($qux); // 3 $func->call($qux); // 3
 +
 +// Or, if we wish to bind
 +$func = Closure::bind(&FooBar::get, $qux);
 </code> </code>
  
Line 67: Line 72:
 When a function is referenced in this manner, an unbound, unscoped ''Closure'' of that function is returned. For a static method, a static, scoped ''Closure'' is given. When a normal method is referenced, an unbound, scoped ''Closure'' is given. When a function is referenced in this manner, an unbound, unscoped ''Closure'' of that function is returned. For a static method, a static, scoped ''Closure'' is given. When a normal method is referenced, an unbound, scoped ''Closure'' is given.
    
-Like the [[rfc:closure_apply|Closure::call]] proposal, we relax the restriction on unbound scoped closures. This is because if we were to give a static method, it could not be bound (useless as it is an instance method), and we don't know what to bind to ahead-of-time. Thus we create an incomplete closure of sorts, which can be called and probably won't work (much like you can statically call an instance method), or can be bound with ''->bindTo'' or ''->call''.+We relax the restriction on unbound scoped closures. This is because if we were to give a static method, it could not be bound (useless as it is an instance method), and we don't know what to bind to ahead-of-time. Thus we create an incomplete closure of sorts, which can be called and probably won't work (much like you can statically call an instance method), or can be bound with ''->bindTo'' or ''->call''. We don't provide any way to produce an unbound scoped closure in userland as this is, aside from function referencing, an obscure use case.
  
-Because the ''->call'' method would be useful here, this RFC depends on [[rfc:losure_apply|that RFC]] passing first, and the patch incorporates the ''->call'' patch.+Because the ''->call'' method would be useful here, this RFC depends on [[rfc:closure_apply|that RFC]] passing first, and the patch incorporates the ''->call'' patch.
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
Line 90: Line 95:
  
 A branch which implements this with a test which incorporates the Closure::call patch and is based on master can be found here: https://github.com/TazeTSchnitzel/php-src/compare/function_reference_with_apply A branch which implements this with a test which incorporates the Closure::call patch and is based on master can be found here: https://github.com/TazeTSchnitzel/php-src/compare/function_reference_with_apply
- 
-===== Implementation ===== 
-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 ===== ===== References =====
Line 101: Line 100:
   * [[https://en.wikipedia.org/wiki/First-class_function|First-class function - Wikipedia]]   * [[https://en.wikipedia.org/wiki/First-class_function|First-class function - Wikipedia]]
   * [[rfc:closure_apply|Closure::call RFC]]   * [[rfc:closure_apply|Closure::call RFC]]
- 
-===== Rejected Features ===== 
-Keep this updated with features that were discussed on the mail lists. 
rfc/function_referencing.1407077891.txt.gz · Last modified: 2017/09/22 13:28 (external edit)