public
function
index() {
echo
'我是 test 下面的 in.php';
}
}
?>
在 test 目录下建立 loader.php,内容如下
代码如下:
<?php
set_include_path("/var/www/test/");
//这里需要将路径放入 include
spl_autoload("in");
//寻找/var/www/test/in.php
$in
=
new
in();
$in
->index();
•spl_autoload_register 将函数注册到 SPL __autoload 函数栈中,修改 loader.php
代码如下:
function
AutoLoad(
$class
){
if
(
$class
== 'in'){
require_once
("/var/www/test/in.php");
}
}
spl_autoload_register('AutoLoad');
$a
=
new
in();
$a
->index();
•spl_autoload_register 注册多个自定义的 autoload 函数的应用
首先在 test 目录下建立 mods 文件夹并建立 inmod.mod.php 内容如下:
代码如下:
<?php
class
inmod
{
function
__construct()
{
echo
'我是 mods 下的 in';
}
}
然后在 test 目录下建立 libs 文件夹并建立 inlib.lib.php 内容如下:
代码如下: