lb5645284 发表于 2017-4-4 14:15:32

set_include_path() get_include_path() __autoload()三个php方法

PHP5中提供一个叫 __autoload() 的方法, 当我们使用一个之前没定义的类或接口时,可以在这个方法中做最后的处理。

function __autoload($className){
//如果是其他类,将类名转为小写
include strtolower($className).".class.php";
}


但一般情况下,在这之前我们需要用 get_include_path() 和 set_include_path() 方法设置include包含文件所在的目录

$include_path=get_include_path();
$include_path.=PATH_SEPARATOR.OURCLASSPATH."/";
set_include_path($include_path);


其中 PATH_SEPARATOR 分隔符号 Linux(:) Windows(;)
页: [1]
查看完整版本: set_include_path() get_include_path() __autoload()三个php方法