日期:2014-05-16 浏览次数:20476 次
<?php
// 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
<?php
class myClass {
public function __construct() {
echo "myClass init'ed successfuly!!!";
}
}
?>
// ./index.php
<?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();
?>