About Spl_autoload_register () and __autoload ()
Look at the use of both:
__autoload usage function __autoload ($classname) {$filename = "./class/". $classname. ". Class.php "; if (Is_file ($filename)) {include $filename;}}
Spl_autoload_register usage spl_autoload_register (' load_class ');
function Load_class ($classname) {$filename = "./class/". $classname. ". Class.php "; if (Is_file ($filename)) {include $filename;}}
The benefits of using Spl_autoload_register () are ineffable: (1) automatic loading of objects is more convenient, and many frameworks do this:
Class Classautoloader {public Function __construct () {spl_autoload_register (Array ($this, ' loader '));} Private function Loader ($className) {echo ' Trying to load ', $className, ' via ', __method__, ' () \ n '; include $className. '. php '; } }
$autoloader = new Classautoloader ();
$obj = new Class1 (); $obj = new Class2 ();
(2) You should know that the __autoload () function can only exist once, spl_autoload_register () can of course register multiple functions
function A () {include ' a.php ';} function B () {include ' b.php ';} spl_autoload_register (' a '); Spl_autoload_register (' B ');
(3) The SPL function is very rich, providing more functions, such as spl_autoload_unregister () logout of registered functions, Spl_autoload_functions () return all registered functions, etc.
The above describes the Spl_autoload_register and __autoload, including the register,auto aspects of the content, I hope that the PHP tutorial interested in a friend helpful.