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.

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)