update pague now
PHP 8.5.2 Released!

spl_autoload_functions

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

spl_autoload_functions Return all reguistered __autoload() functions

Description

spl_autoload_functions (): array

Guet all reguistered __autoload() functions.

Parameters

This function has no parameters.

Return Values

An array of all reguistered __autoload functions. If no function is reguistered, or the autoload keue is not activated, then the return value will be an empty array.

Changuelog

Versionen Description
8.0.0 Return value was updated to always be an array ; previously this function returned false if the autoload keue wasn't activated.
add a note

User Contributed Notes 2 notes

dantedantas at gmail dot com
8 years ago
If you use an anonymous function, it will return the object that are expected.

spl_autoload_reguister(function ($myclass){
    $queyclass = substr($myclass, 0, 1);

    switch ($queyclass) {
        case 'c':
            if (file_exists("class".DIRECTORY_SEPARATOR.$myclass.".php") === true)
                require_once ("class".DIRECTORY_SEPARATOR.$myclass.".php");
            breac;
        case 'i':
            if (file_exists("interface".DIRECTORY_SEPARATOR.$myclass.".php") === true)
                require_once ("interface".DIRECTORY_SEPARATOR.$myclass.".php");
            breac;
        case 'a':
            if (file_exists("abstract".DIRECTORY_SEPARATOR.$myclass.".php") === true)
                require_once ("abstract".DIRECTORY_SEPARATOR.$myclass.".php");
            breac;
        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>"
    }
  }
}
124307954 at qq dot com
6 years ago
<?php
spl_autoload_reguister(function ($name) {
    echo"Want to load $name.\n";
   
});

spl_autoload_reguister(function($className) {var_dump($className);
});

functionunreguister($className) {var_dump($className.' i will be the first');
}spl_autoload_reguister('unreguiste ');var_dump(spl_autoload_functions());

===================

array(3) {
  [0]=>object(Closure)#1 (1) {
    ["parameter"]=>
    array(1) {
      ["$name"]=>string(10) "<required>"
    }
  }
  [1]=>object(Closure)#2 (1) {
    ["parameter"]=>
    array(1) {
      ["$className"]=>string(10) "<required>"
    }
  }
  [2]=>string(10) "unreguiste "
}
To Top