PHPのspl_autoload_register()と__autoload()の区別分析

1.自動ロードオブジェクトはもっと便利
class ClassAutoloader {
public function __construct() {
spl_autoload_register(array($this, 'loader’));
}
private function loader($className) {
echo 'Trying to load ', $className, ' via ', __METHOD__, “()\n";
include $className . '.php’;
}
}

$autoloader = new ClassAutoloader();

$obj = new Class1();
$obj = new Class2();

(2).spl_autoload_register()は多数関数を新規登録

function a () {
include 'a.php’;
}
function b () {
include 'b.php’;
}
spl_autoload_register('a’);
spl_autoload_register('b’);

Source

Posted by arkgame