Home >Backend Development >PHP Tutorial >Detailed explanation of the usage of php function spl_autoload_register
Then, there is an index.php that needs to be used To this class A, the conventional writing method is:
Problem : If index.php needs to contain not just class A, but many classes, you must write many lines of require statements. In php5, the __autoload function is automatically called when trying to use a class that has not been defined, so you can let php automatically load the class by writing the __autoload function. The above example can be modified as:
Continue to modify the above example: function loader($class) { class Loader { public static function loadClass($class) { $file = $class . '.php';if (is_file($file)) { require_once($file); } }
|