This function is very useful at first glance, especially when there are many class files in your class, some netizens test it, __autoload () has little impact on performance, this method is triggered when the PHP engine encounters a class that is not instantiated. for example, the blog system I wrote will do this during initialization:
This function is very useful at first glance, especially when there are many class files in your class, some netizens test it, __autoload () has little impact on performance, this method is triggered when the PHP engine encounters a class that is not instantiated. for example, the blog system I wrote will do this during initialization:
/*** Automatically load the relevant class library file * by www.phpddt.com */function _ autoload ($ classname) {if (substr ($ classname,-6) = "Action ") {include APP_PATH. 'controllers /'. $ classname. '. class. php ';} elseif (substr ($ classname,-5) = "Model") {include APP_PATH. 'Models /'. $ classname. '. class. php ';} elseif ($ classname = "Smarty") {include SYSTEM_PATH. 'smarty/smarty. class. php ';} else {include APP_PATH. 'Common /'. $ classname. '. class. php ';}}
There is also a method to include paths:
Function _ autoload ($ class_name) {$ path = str_replace ('_', DIRECTORY_SEPARATOR, $ class_name); require_once $ path. '. php ';}
Converts an underline to a directory separator (DIRECTORY_SEPARATOR). This will make your management library files very effective!