Load class files in PHP, commonly used require statements or include statements. The difference is that the Require statement contains a file that, if there is a syntax error or does not exist, prompts the error "fatal error" and terminates the program; The include statement, in the same case, prompts the warning "warning" and the program continues to run.
PHP load class files can also be used require_once or include_once, they are different from the Require statement or include statement: the inclusion of the file will check whether the same file is already included, if any, it will not be repeated. However, the use of require_once or include_once is difficult to avoid, resulting in a decrease in efficiency.
Starting with PHP5, you can implement automatic loading of classes by defining a _autoload () function. This function is called automatically when PHP attempts to use an undefined class.
_autoload () Usage:
./myclass.php
<?phpclass myClass {public function __construct () { echo "MyClass init ' ed successfuly!!!"; }}? >
./index.php
<?phpfunction __autoload ($classname) { $filename = "./". $classname. ". PHP "; Include_once ($filename);} $obj = new MyClass ();? >
Several ways to load class files in PHP