douhan4812 2010-01-02 15:03
浏览 79

当脚本从命令行运行时,sp​​l_autoload失败

I know this has to do with the path not being quite right but it has me baffled. I can run my script with no problems at all from the browser but when I do to the exact same spot from a shell, spl_autoload complains and dies:

Fatal error: spl_autoload(): Class db could not be loaded in...

I am using the absolute path from the root directory, echoed to screen and pasted it into a shell and verified that it is good. Please... what am I missing??

  • 写回答

2条回答 默认 最新

  • douzhao6584 2010-01-02 15:30
    关注

    Try using the __DIR__ constant to locate the files, CLI PHP doesn't uses the same working dir.

    Use something like this:

    function __autoload($class)
    {
        require_once(dirname(__FILE__) . '/path/to/libraries/' . $class . '.php');
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作