spl_autoload_functions

(PHP 5 >= 5.1.2, PHP 7)

spl_autoload_functionsReturn all registered __autoload() functions

Description

array spl_autoload_functions ( void )

Get all registered __autoload() functions.

Parameters

This function has no parameters.

Return Values

An array of all registered __autoload functions. If the autoload queue is not activated then the return value is FALSE. If no function is registered the return value will be an empty array.

add a note add a note

User Contributed Notes 1 note

up
1
dantedantas at gmail dot com
5 months ago
If you use an anonymous function, it will return the object that are expected.

spl_autoload_register(function ($myclass){
    $keyclass = substr($myclass, 0, 1);

    switch ($keyclass) {
        case 'c':
            if (file_exists("class".DIRECTORY_SEPARATOR.$myclass.".php") === true)
                require_once ("class".DIRECTORY_SEPARATOR.$myclass.".php");
            break;
        case 'i':
            if (file_exists("interface".DIRECTORY_SEPARATOR.$myclass.".php") === true)
                require_once ("interface".DIRECTORY_SEPARATOR.$myclass.".php");
            break;
        case 'a':
            if (file_exists("abstract".DIRECTORY_SEPARATOR.$myclass.".php") === true)
                require_once ("abstract".DIRECTORY_SEPARATOR.$myclass.".php");
            break;
        default:
            if (file_exists($myclass.".php") === true)
                require_once ($myclass.".php");
    }

/******************************/

var_dump(spl_autoload_functions()) return:

array(1) {
  [0]=>
  object(Closure)#1 (1) {
    ["parameter"]=>
    array(1) {
      ["$myclass"]=>
      string(10) "<required>"
    }
  }
}
To Top