The Spl_autoload method in PHP5 is equivalent to implementing its own __autoload
<? PHP function __autoload ($classname) { if(is_file($classname . '. php ') { include$classname. php '; ElseIf (is_file($classname. Inc ') { include$classname. Inc '; } }
It will automatically look for a. php/.inc file with the same name as $classname in the registration directory. Of course, you can also specify a specific file by registering the extension
<? php spl_autoload_extensions ('. Php,.inc,.some ');
So how do you load Spl_autoload automatically, by
<? php spl_autoload_register ();
Spl_autoload_register has a $callback parameter, if not specified, it will automatically register spl_autoload, in order to be able to search for more automatic loading directory, you can set the automatic loading directory before the code
<? PHP Set_include_path (Get_include_path(). Path_separator. ' Some/path '. Directory_separator);
These methods are commonly used in PHP frameworks.