The __autoload () function can implement the required classes for automatic loading
Usage:
__autoload () When instantiating an object, the method is automatically called to load if no related file is introduced.
Instance:
Public Function __autoload ($className) { $actionPath = "e://project/lib/action/". $className. ". Class.php ", if (!file_exists ($actionPath)) { echo $actionPath. Path does not exist "; } Require_once ($actionPath);}
Spl_autoload_register () function
Role: Registering a custom load function
For example, defining a loadfile () as a custom load function in a file, but after at least declaring or defining the function, when instantiating an object, the program does not automatically run the LoadFile () function, but automatically runs the __autoload () function. The Spl_autoload_register () function is to let the program automatically invoke the LoadFile () function when instantiating an object.
Instance:
TestLoad ();? >
Result: Output: This is the TestLoad method in the test class;
Spl_autoload_register () has three parameters
The first: Array ($classname, $method), is an array with two elements, the first element represents the class where the auto-load method resides, and the second represents the function name of the auto-load method
Second parameter: Indicates whether an exception is thrown when the registration cannot be successful, True/false
The third parameter, True/false, indicates whether the function is registered to the top of the auto-load function queue.
Note: 1, spl_autoload_register () actually created the queue of the AutoLoad function, executed one by one in the order defined (so far I did not successfully implement one-by-one functions, please point out)
2, if the use of Spl_autoload_register () register a new automatic loading function, then the original __autoload () function will be invalidated, if you need to use the __autoload () function, you need to pass the Spl_autoload_register () To register the __autoload () function again, you can use this function