At the very beginning, when we use one or more classes, it is generally necessary to use the require or include function to introduce the class before it can be used;
But when there are so many classes in a project, we have to introduce them all in one file when we use them, so
On the one hand is more cumbersome, not high efficiency. On the other hand, when we delete some of these classes, we are going to delete the corresponding require or include
statement, error prone;
To avoid the above situation, we used the PHP Magic function __autoload () to avoid the introduction of the class in the above cases,
But the new problems have arisen again. When one of our projects uses multiple frames, if the __autoload () function is used in each frame,
Then there will be a fatal error with the function repeating definition;
To solve this problem, the Sql_autoload_register () function appears in php5.3 and later versions, using this function we can
Registering a custom AutoLoad function solves the problem of duplicate function definition;
So many times now we are using the Sql_autoload_register () function to implement automatic loading of classes;
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above describes the PHP object-oriented oop-class automatic loading of the thought process, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.