rfc:function_autoloading

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
rfc:function_autoloading [2013/08/30 11:11] – Fix incorrect constant values ircmaxellrfc:function_autoloading [2013/08/30 11:39] – Update example code to show not needing a switch ircmaxell
Line 76: Line 76:
 php\autoload_register(function($name, $type) { php\autoload_register(function($name, $type) {
     var_dump($name, $type);     var_dump($name, $type);
-    switch ($type) { +    eval("function $name(){}"); 
-        case php\AUTOLOAD_FUNCTION: +    // We don't need a switchsince we only register for functions.
-            eval("function $name(){}"); +
-            break; +
-        case php\AUTOLOAD_CLASS: +
-            eval("class $name {}"); +
-            break; +
-        case php\AUTOLOAD_CONSTANT: +
-            define($name$name); +
-            break; +
-    }+
 }, php\AUTOLOAD_FUNCTION); }, php\AUTOLOAD_FUNCTION);
 foo(); // string(3) "foo" int(2) foo(); // string(3) "foo" int(2)
Line 104: Line 95:
         case php\AUTOLOAD_FUNCTION:         case php\AUTOLOAD_FUNCTION:
             eval("function $name(){}");             eval("function $name(){}");
-            break; 
-        case php\AUTOLOAD_CLASS: 
-            eval("class $name {}"); 
             break;             break;
         case php\AUTOLOAD_CONSTANT:         case php\AUTOLOAD_CONSTANT:
rfc/function_autoloading.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1