说明:自动加载类文件到本文件。 我们在用PHP4的时候一般用类的过程应该是这样的: 类文件加载require(类.php) 或include(类.php) $test = new 类名 然后使用类方法。 php5以后就不用了,因为PHP5提供了一个简洁方便的方法,那就是autoload 具体举例说明: test.php类文件(用与自动加载)
<?PHP
class test{//类开始
function echo_str(){print "this is test files";}
}//类结束
?>
testone.php文件
<?PHP
$a = new test;
$a->echo_str();
function __autoload(strtolower($className)){ //strtolower是自动转化为小写字母(当然你可以不用strtolower,因为php5会自动将其转化为小写的)
require_once($className.".php"); //自动加载类文件,根据类的名称给予文件名(即为加载规则)
}
?>
转自:http://fuyuanjin.phpx.com/happy/thread-145034-1-1.html