Home >Backend Development >PHP Tutorial >PHP autoload classes
<span style="white-space:pre"> </span>方法一:在类外面写 function __autoload($name){
<span style="white-space:pre"> </span>//处理$name,获得类路径 include $name_path; } //类内注册 class ClassA{
<span style="white-space:pre"> </span>public static $_autoload; public function __construct(){ spl_autoload_register(array('ClassA','classAutoLoader')); } //ClassA 如果实例化可以不用静态方法 public static function classAutoLoader($name){ <pre name="code" class="php"><span style="white-space:pre"> </span>//处理$name,获得类路径 include $name_path;}}
The above introduces the PHP automatic loading class, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.