rfc:true-nested-function-support

This is an old revision of the document!


Request for Comments: How to write RFCs

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)