PHP面向对象----- 类的自动加载
1、类的自动加载
spl_autoload_register函数
test.php
<?php spl_autoload_register('autoload'); // require_once "Test1.php"; // require_once "Test2.php"; function autoload($class) { require __DIR__.'/'.$class.".php"; } Test1::index(); Test2::index();
Test1.php
<?php class Test1 { public static function index() { echo "Hello world,I am test1<br/>"; } }
Test2.php
<?php class Test2 { static function index() { echo "Hello world,I am test2<br/>"; } }