- /* autoload.php */
- function __autoload($classname) {
- require_once ($classname . 「class.php」);
- }
- $person = new Person(」Altair」, 6);
- var_dump ($person);
- ?>
- $paths[] = BP . DS . ‘app’ . DS . ‘local’;
- $paths[] = BP . DS . ‘app’ . DS . ‘base’;
- $paths[] = BP . DS . ‘lib’;
- $appPath = implode(PS, $paths);
- set_include_path($appPath . PS . get_include_path());
- class Autoload {
- /**
- * 自身對象
- *
- */
- protected static $_instance = null;
- public function __construct() {
- }
- /*
- * 實例化自身
- *
- */
- public static function instance() {
- if (null == self::$_instance) {
- self::$_instance = new self();
- }
- return self::$_instance;
- }
- /**
- *
- * 註冊自動加載函數
- */
- public static function register() {
- spl_autoload_register(array(self::instance(), ‘autoload’));
- }
- /*
- *
- * 自動加載類
- */
- public function autoload($class) {
- if (!is_string($class)) {
- return;
- }
- $classFile = str_replace(‘ ‘, DS, ucwords(str_replace(‘_’, ‘ ‘, $class)));
- $classFile .= ‘.php’;
- return include $classFile;
- }
- }