php调用不同目录的类
1、首先php把不同目录的类的相对路径存入数组,然后使用循环引入类<?php
header('Content-type:text/html;charset=utf-8');
//spl_autoload_register()参数是匿名函数
spl_autoload_register(function($ClassName){
//将不同路径的类文件的路径放入数组中;
$arr = array(
"./$ClassName.class.php",
"./admin/controller/$ClassName.class.php"
);
// 循环不同路径的类文件的数组
foreach ($arr as $filename) {
if (file_exists($filename)) {
require_once($filename);
}
}
});
2、使用new关键字创建对象并调用即可$obj = new Student();
$obj->ShowInfo();
$obj2 = new Fruit();
$obj2->ShowInfo();
类文件:命名为Student.class.php<?php
hea