开发者社区 问答 正文

php5.5 下静态类 不能用 自动类加载器加载?报错

php5.4下可以加载

但服务器是php5.5 直接报错

展开
收起
爱吃鱼的程序员 2020-06-22 14:00:06 479 分享 版权
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    1.建议用spl_autoload_register

    2.你的autoload就一个var_dump?没有include/require?

    这是不可能的。肯定是你的用法有误。

    什么叫静态类?

    <?phpclassGenerator{publicstaticfunctiongetRandomDate($startDate='2011-1-1',$endDate='2013-11-25'){$days=(strtotime($endDate)-strtotime($startDate))/86400;$ts=strtotime($startDate)+rand(0,$days)*86400;returndate('Y-m-d',$ts);}}                                                                                                                    



    b.php

     

    function__autoload($name){var_dump($name);}$date=Generator::getRandomDate();echo$data;




    我记得一直都不可以呀,楼主上哪看的资料,静态类也可以动态加载?一直可以,貌似generator被php5.5用作关键字了,换个名字就可以了
    2020-06-22 14:00:22
    赞同 展开评论
问答标签:
问答地址: