Fatal error: spl_autoload(): Class Test could not be loaded in /home/vilay/www/spl/index.php

来源:5-1 SPL使用spl_autoload_register函数装载类

慕莱坞4304824

2015-03-01 21:46

spl_autoload_extensions('.class.php');

    define('CLASS_DIR','Class/');

    set_include_path(get_include_path().PATH_SEPARATOR.CLASS_DIR);

    spl_autoload_register();

    new Test();


写回答 关注

2回答

  • pher
    2016-11-02 12:00:18

    你使用的是默认的spl_autoload() 函数,这个函数的默认extension参数是会把类名自动转换为小写,在加上后缀名也就是spl_autoload_extensions()设置的后缀。

    如果想要实现大写,你可以自己实现一个类加载方法, 让后spl_autoload_register() 注册这个函数,这样应该可以满足你的DIY 需求。这种方式也是很多PHP框架实现的方式

  • 慕莱坞4304824
    2015-03-01 21:57:40

    找到原因了,类名要小写,Test.class.php,不行,需要test.class.php

    慕莱坞430...

    但是如果要写成大写,不懂需要怎么配置

    2015-03-01 21:58:45

    共 1 条回复 >

站在巨人的肩膀上写代码—SPL

SPL,一个能找到登上绝顶的天梯,学会后能提高实际工作的效率

22776 学习 · 108 问题

查看课程

相似问题