rfc:true-nested-function-support

Differences

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

Link to this comparison view

Next revision
Previous revision
rfc:true-nested-function-support [2011/07/18 12:23] – created runerfc:true-nested-function-support [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== Request for Comments: How to write RFCs ======+====== Request for Comments: True nested function support ======
   * Version: 1.0   * Version: 1.0
   * Date: 2011-06-18   * Date: 2011-06-18
Line 13: Line 13:
   * If the parent function is called twice they will be defined twice and thus give a fatal error.   * If the parent function is called twice they will be defined twice and thus give a fatal error.
  
-This is how it is possible to implemented nested functions today:+===== Code examples =====
  
-1) Extending the functionname and wrapping in function_exists().+====== 1) Current idiomatic usage of helper functions ====== 
 +<code php> 
 +    function _prefix_functionname_helperfunctionname($arg1, $arg2) { 
 +        ; 
 +    } 
 +            
 +    function prefix_functionname() { 
 +       // Code here... 
 +       somefunc(prefix_functionname_helperfunctionname($arg1, $arg2)); 
 +    } 
 +</code> 
 + 
 +====== 2) Appending the function name and wrapping in function_exists() ======
 <code php> <code php>
     function prefix_functionname() {     function prefix_functionname() {
Line 28: Line 40:
 </code> </code>
  
-2) Using closures.+====== 3) Using closures ======
 <code php> <code php>
     function prefix_functionname() {     function prefix_functionname() {
-       $innerfunctionname = function prefix_functionname_innerfunctionname($arg1, $arg2) {+       $innerfunctionname = function ($arg1, $arg2) { 
 +           ;
        }        }
        // Code here...        // Code here...
-       $innerfunctionname($arg1, $arg2);+       somefunc($innerfunctionname($arg1, $arg2));
     }     }
 </code> </code>
  
- +====== 4) Using new syntax ====== 
 +<code php> 
 +    function prefix_functionname() { 
 +       function innerfunctionname($arg1, $arg2) { 
 +           ; 
 +       } 
 +       // Code here... 
 +       somefunc(innerfunctionname($arg1, $arg2)); 
 +    } 
 +</code>
  
 ===== Todo for this RFC ===== ===== Todo for this RFC =====
-  * Write little script that checks for use of internal functions in common frameworks like Symphony and Zend.+  * Write little script that checks for the current use of nested functions in common frameworks like Symphony and Zend. I am assuming this is zero.
  
rfc/true-nested-function-support.1310991838.txt.gz · Last modified: 2017/09/22 13:28 (external edit)