我从 http://www.php.net/manual/ru/function.spl-autoload.php#92767得到这个例子
但这会导致错误 *致命错误:spl_autoload() [function.spl-autoload]: Class space could not be loaded in C:\my_projects\site.local\www\index.php on line 18*
/index.php
// Your custom class dir
define('CLASS_DIR', 'oop/classes');
// Add your class dir to include path
set_include_path(get_include_path().PATH_SEPARATOR.CLASS_DIR);
// You can use this trick to make autoloader look for commonly used "My.class.php" type filenames
spl_autoload_extensions('.class.php');
// Use default autoload implementation
spl_autoload_register();
new space/my;
/oop/classes/space/my.class.php
namespace space;
class my{
public function __construct{
var_dump('space class was here!');
}
}
我知道 PSR-0,但就我而言,我需要了解内置函数的工作原理