php.net
Many developers writing object-oriented applications create one PHP source file per class definition.
One of the biggest annoyances is having to write a long list of needed includes at the beginning of each script (one for each class).
很多开发者写面向对象的应用程序时对每个类的定义建立一个 PHP 源文件。
一个很大的烦恼是不得不在每个脚本开头写一个长长的包含文件列表(每个类一个文件)。
<?php
function my_autoloader($class){
include 'classes/'.$class.'.class.php'; }
spl_autoload_register('my_autoloader');
$obj = new MyClass();
<?php
//Or, using an anonymous function
spl_autoload_register(function($class){
include 'classes/'.$class.'.class.php';
}); $obj = new MyClass();