Home > Article > Backend Development > HidRegisterMinidriver PHP spl_autoload_register implements automatic loading research
Here we talk about some characteristics of this function through an experiment.
Function prototype
bool spl_autoload_register ([ callback $autoload_function [, bool $throw = true [, bool $prepend = false ]]] )
Version compatible
PHP 5 >= 5.1.2
Experimental process
Step one, use The spl_autoload_register() function registers the load() method
Copy the code The code is as follows:
function load(){
require_once 'lib.php';
}
spl_autoload_register('load') ;
?>
Copy the code The code is as follows:
class className{
function method(){
echo 'a method in class
Class
Copy code
The code is as follows:
onlyMethod(); Output: a method in class
method onlyExplanation: Instantiate the className class, call the class method() function, and call the onlyMethod() method at the same time. The output is normal and no errors occur.
The third step, directly call the function
onlyMethod();
Explanation: There is no instantiated class , directly call the onlyMethod() function in the lib.php file
Output: