rfc:true-nested-function-support
This is an old revision of the document!
Request for Comments: How to write RFCs
- Version: 1.0
- Date: 2011-06-18
- Author: Rune Kaagaard rumi.kg@gmail.com
- Status: Draft
- First Published at: https://wiki.php.net/rfc/true-nested-function-support
Introduction
Stub
Why nested functions are useless at the moment
- They exist in the global namespace.
- 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:
1) Extending the functionname and wrapping in function_exists().
function prefix_functionname() { if (!function_exists('prefix_functionname_innerfunctionname')) { function prefix_functionname_innerfunctionname($arg1, $arg2) { ; } } // Code here... somefunc(prefix_functionname_innerfunctionname($arg1, $arg2)); }
2) Using closures.
function prefix_functionname() { $innerfunctionname = function prefix_functionname_innerfunctionname($arg1, $arg2) { } // Code here... $innerfunctionname($arg1, $arg2); }
Todo for this RFC
- Write little script that checks for use of internal functions in common frameworks like Symphony and Zend.
rfc/true-nested-function-support.1310991838.txt.gz · Last modified: 2017/09/22 13:28 (external edit)