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.
Code examples
1) Appending the function name 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 ($arg1, $arg2) { ; } // Code here... somefunc($innerfunctionname($arg1, $arg2)); }
3) Using new syntax
function prefix_functionname() { function prefix_functionname_innerfunctionname($arg1, $arg2) { ; } // Code here... somefunc(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.1310992109.txt.gz · Last modified: 2017/09/22 13:28 (external edit)