./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();
?>
_autoload()是php中的一个魔术方法,在代码中当调用不存在的类时会自动调用该方法。
使用该__autoload()方法就可以避免调用其他类时,频繁使用require函数。
