开发者

Strange behaviour for spl_autoload on phpfog

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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜