根据
PHP页面
spl_autoload_register( )
的最高评论:
Good news for PHP 5.3 users with namespaced classes:
When you create a subfolder structure matching the namespaces of the >containing classes,you will never even have to define an autoloader.
<?PHP spl_autoload_extensions(".PHP"); // comma-separated list spl_autoload_register(); ?>
但是,当我有以下结构时:
* classes / someclass.PHP
* index.PHP
<?PHP class someclass { function __construct( ) { echo 'It works!'; } } ?>
和index.PHP包含:
<?PHP spl_autoload_extensions(".PHP"); spl_autoload_register(); new classes\someclass; ?>
然后我收到以下错误:
Fatal error: spl_autoload(): Class classes\someclass could not be
loaded
我错了吗?我怎样才能做到这一点?
从评论
这对于班级不起作用:
<?PHP namespace classes; class someclass { function __construct( ) { echo 'It works!'; } } ?>