rfc:function_autoloading4

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
rfc:function_autoloading4 [2024/09/03 21:07] – clarity and making the api more ergonomic withinboredomrfc:function_autoloading4 [2024/09/04 19:07] (current) – fix example withinboredom
Line 30: Line 30:
 <?php <?php
  
-spl_autoload_register(function ($function, $type) { +spl_autoload_register(function ($function) { 
-    if ($type === SPL_AUTOLOAD_FUNCTION) { +    $function_path = dirname(str_replace('\\', DIRECTORY_SEPARATOR, $function)); 
-        $function_path = dirname(str_replace('\\', DIRECTORY_SEPARATOR, $function)); +    $file = __DIR__ . '/functions/' . $function_path . '.php';
-        $file = __DIR__ . '/functions/' . $function_path . '.php';+
  
-        if (file_exists($file)) { +    if (file_exists($file)) { 
-            require_once $file; +        require_once $file;
-        }+
     }     }
 }, false, false, SPL_AUTOLOAD_FUNCTION); }, false, false, SPL_AUTOLOAD_FUNCTION);
Line 64: Line 62:
 The ''%%spl_autoload_call%%'' function will be modified to accept a second parameter of one or both of the constants, with the default value set to ''%%SPL_AUTOLOAD_CLASS%%''. The name of the first parameter will be changed to ''%%$name%%'' to reflect that it can be a class or function name. The ''%%spl_autoload_call%%'' function will be modified to accept a second parameter of one or both of the constants, with the default value set to ''%%SPL_AUTOLOAD_CLASS%%''. The name of the first parameter will be changed to ''%%$name%%'' to reflect that it can be a class or function name.
  
-In the event that both constants are passed, it will attempt to autoload both types. This may be useful in the case where functions and invocable classes are used interchangeably.+In the event that both constants are passed, it will attempt to autoload both types.
  
 <code php> <code php>
rfc/function_autoloading4.1725397657.txt.gz · Last modified: 2024/09/03 21:07 by withinboredom