In the beginning, when we use one or more classes, we usually use the require or include function to introduce the class before it can be used;
But when there are a lot of classes in a project, then When we all use these classes, we must introduce them all in one file, which is cumbersome and inefficient on the one hand. On the other hand, when we delete some of the classes, we have to delete the corresponding require or include statements, which is prone to errors;
In order to avoid the above situation, we used the magic of PHP Function __autoload() to avoid the above situation of introducing classes multiple times,
But new problems have arisen. When one of our projects uses multiple frameworks, if the __autoload() function is used in each framework,
then a fatal error of duplicate function definition will occur;
In order to solve this problem , the sql_autoload_register() function appeared in php5.3 and later versions. Using this function, we can register our own custom autoload function, which solves the problem of repeated function definitions;
So now many times we The sql_autoload_register() function is used to implement automatic loading of classes;
Copyright Statement: This article is an original article by the blogger and may not be reproduced without the permission of the blogger.
The above introduces the thought process of PHP object-oriented OOP-class automatic loading, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.