| php自动加载类使用:目录结构
  index的代码展示 <?php
header("Content-type:text/html;charset=utf-8"); 
ini_set("date.timezone", "Asia/Shanghai");
const APP_PATH = __DIR__ . '/';
const Lib = '../PHPmm/';
const Resource = APP_PATH . 'Resource';
ini_set('display_errors', 1);
require Lib . 'PHPmm.php';  
$app = new  PHPmm();
$app->run();
$app = null;
 PHPmm.php代码展示 <?php
class PHPmm
{
    
    public function run()
    {
        spl_autoload_register(array($this, 'load'));
        $testa = new a();
        $testa->b();
    }
    private function load($className)
    {
        require Lib . $className . '.class.php';
    }
}
 a.class.php的代码展示 <?php
class a
{
    public function b()
    {
        echo 'hello ,你好';
    }
}
 b.class.php的代码展示 <?php
class b
{
    public function hello()
    {
        echo 'PHPmm';
    }
}
 如果  
 // $jobb = new b();// $jobb->hello();
 被注释的话
 运行效果
 为 hello ,你好
 否则 hello ,你好PHPmm
 成功学习phpphp自动加载类使用 |