时间:2021-07-01 10:21:17 帮助过:18人阅读
// PHP5 Used __autoload function
$obj_A = new clsA(); // in "cls" directory!
$obj_B = new clsB(); // in "cls/cls" directory!
function __autoload($className){
if(strtolowwer($className) == "clsb"){
require_once "cls/cls/$className.php";
}else{
include_once "cls/$className.php";
}
}
?>
// ./myClass.php
class myClass {
public function __construct() {
echo "myClass init'ed successfuly!!!";
}
}
?>
// ./index.php
// we've writen this code where we need
function __autoload($classname) {
$filename = "./". $classname .".php";
include_once($filename);
}
// we've called a class ***
$obj = new myClass();
?>