: This article mainly introduces PHP auto-loading. if you are interested in PHP tutorials, refer to it. Automatic loading of classes
On the external page, you do not need to introduce class files, but the program will automatically "dynamically load" the class when it needs a class.
- When creating an object, new
- Directly use a class name (operate static attributes and methods)
Use the _ autoload magic function
This function will be called in two cases. this function needs to be pre-defined to write general statements for loading class files.
function__autoload($name){require'./lib/'.$name.'.class.php';}
Use spl_autoload_register ()
Use it to register (declare) multiple functions that can replace _ autoload (). Naturally, you have to define these functions, and the function functions the same as _ autoload, however, in this case, we can deal with more situations.
// Register the function spl_autoload_register ("model") for automatic loading; spl_autoload_register ("controll"); // define two functions functionmodel ($ name) {$ file = 'respectively '. /model /'. $ name. '. class. php '; if (file_exists ($ file) {require '. /model /'. $ name. '. class. php ';} // if a class is required, but the current page does not load the class. // model () and controll () are called in sequence until the class file is found to be loaded, otherwise, the error functioncontroll ($ name) {$ file = '. /controll /'. $ name. '. class. php '; if (file_exists ($ file) {require '. /controll /'. $ name. '. class. php ';}}
'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
'). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script
The above introduces PHP auto-loading, including some content, and hopes to help friends who are interested in PHP tutorials.