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 revision
Previous revision
Next revisionBoth sides next revision
rfc:function_autoloading [2013/08/30 01:20] – Update Title ircmaxellrfc:function_autoloading [2013/08/30 11:39] – Update example code to show not needing a switch ircmaxell
Line 24: Line 24:
    * //php\AUTOLOAD_CLASS => 1// - Represents Class autoloading    * //php\AUTOLOAD_CLASS => 1// - Represents Class autoloading
    * //php\AUTOLOAD_FUNCTION => 2// - Represents Function autoloading    * //php\AUTOLOAD_FUNCTION => 2// - Represents Function autoloading
-   * //php\AUTOLOAD_CONSTANT => 3// - Represents Constant autoloading+   * //php\AUTOLOAD_CONSTANT => 4// - Represents Constant autoloading
  
 ==== Functions ==== ==== Functions ====
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:
Line 238: Line 226:
    * //php\AUTOLOAD_CLASS => 1// - Represents Class autoloading    * //php\AUTOLOAD_CLASS => 1// - Represents Class autoloading
    * //php\AUTOLOAD_FUNCTION => 2// - Represents Function autoloading    * //php\AUTOLOAD_FUNCTION => 2// - Represents Function autoloading
-   * //php\AUTOLOAD_CONSTANT => 3// - Represents Constant autoloading+   * //php\AUTOLOAD_CONSTANT => 4// - Represents Constant autoloading
  
 ===== php.ini Defaults ===== ===== php.ini Defaults =====
rfc/function_autoloading.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1