phpfog 上 spl_autoload 的奇怪行为

发布于 2024-11-16 22:04:37 字数 1195 浏览 3 评论 0原文

我只是想在 PHP Fog 上构建我的第一个应用程序,但有一段代码无法正常运行 - 但在本地主机和其他常规主机上运行良好。

我使用 TinyMVC 的修改版本,这是负责设置自动加载的代码:

    /* Set include_path for spl_autoload */
    set_include_path(get_include_path()
      . PATH_SEPARATOR . FRAMEWORK_BASEDIR . 'core' . DS
      . PATH_SEPARATOR . FRAMEWORK_BASEDIR . 'libraries' . DS
      . PATH_SEPARATOR . FRAMEWORK_APPLICATION . DS . 'controllers' . DS
      . PATH_SEPARATOR . FRAMEWORK_APPLICATION . DS . 'models' . DS
      );

    /* File extensions to include */ 
    spl_autoload_extensions('.php,.inc');

    /* Setup __autoload */
    $spl_funcs = spl_autoload_functions();
    if($spl_funcs === false)
        spl_autoload_register();
    elseif(!in_array('spl_autoload',$spl_funcs))
        spl_autoload_register('spl_autoload');

基本上,它在应该加载的第一个类处失败,该类位于“FRAMEWORK_BASEDIR . 'core' . DS”中。类文件名是“framework_controller.php”,类名称是“Framework_Controller”(也尝试小写)。如果我手动包含该类,它可以工作,但自动加载会失败。

这是我收到的错误消息:

Fatal error: spl_autoload(): Class Framework_Controller could not be loaded in /var/fog/apps/app7396/claudiu.phpfogapp.com/application/controllers/home.php on line 12 

对于可能出现的问题有什么想法吗?

I'm just trying to build my first app on PHP Fog but there's a piece of code that doesn't run properly - works fine on localhost and other regular hosts though.

I use a modified version of TinyMVC, this is the code responsible for setting up autoloading:

    /* Set include_path for spl_autoload */
    set_include_path(get_include_path()
      . PATH_SEPARATOR . FRAMEWORK_BASEDIR . 'core' . DS
      . PATH_SEPARATOR . FRAMEWORK_BASEDIR . 'libraries' . DS
      . PATH_SEPARATOR . FRAMEWORK_APPLICATION . DS . 'controllers' . DS
      . PATH_SEPARATOR . FRAMEWORK_APPLICATION . DS . 'models' . DS
      );

    /* File extensions to include */ 
    spl_autoload_extensions('.php,.inc');

    /* Setup __autoload */
    $spl_funcs = spl_autoload_functions();
    if($spl_funcs === false)
        spl_autoload_register();
    elseif(!in_array('spl_autoload',$spl_funcs))
        spl_autoload_register('spl_autoload');

Basically, it fails at the first class it should load, which is located in "FRAMEWORK_BASEDIR . 'core' . DS". The class filename is "framework_controller.php" and class name is "Framework_Controller" (tried lowercase as well). If I include the class manually it works but fails with autoload.

Here's the error message that I get:

Fatal error: spl_autoload(): Class Framework_Controller could not be loaded in /var/fog/apps/app7396/claudiu.phpfogapp.com/application/controllers/home.php on line 12 

Any ideas as to what could the problem be?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断舍离 2024-11-23 22:04:37

我设法解决了这个问题:

function framework_autoload($className, $extList='.inc,.php') {

    $autoload_paths = array (
            FRAMEWORK_BASEDIR . 'core' . DS,
            FRAMEWORK_BASEDIR . 'libraries' . DS,
            FRAMEWORK_APPLICATION . DS . 'controllers' . DS,
            FRAMEWORK_APPLICATION . DS . 'models' . DS
        );

      $ext = explode(',',$extList);
      foreach($ext as $x) {
        foreach ($autoload_paths as $v) {
            $fname = $v . strtolower($className).$x;
            if(@file_exists($fname)) {
                require_once($fname);
                return true;
            }
        }
      }
      return false;
}
spl_autoload_register('framework_autoload');

感谢StackOverflow上的另一个问题:spl_autoload问题

I managed to sort it out:

function framework_autoload($className, $extList='.inc,.php') {

    $autoload_paths = array (
            FRAMEWORK_BASEDIR . 'core' . DS,
            FRAMEWORK_BASEDIR . 'libraries' . DS,
            FRAMEWORK_APPLICATION . DS . 'controllers' . DS,
            FRAMEWORK_APPLICATION . DS . 'models' . DS
        );

      $ext = explode(',',$extList);
      foreach($ext as $x) {
        foreach ($autoload_paths as $v) {
            $fname = $v . strtolower($className).$x;
            if(@file_exists($fname)) {
                require_once($fname);
                return true;
            }
        }
      }
      return false;
}
spl_autoload_register('framework_autoload');

Thanks to another question here on StackOverflow: spl_autoload problem

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文