buseni
V2EX  ›  问与答

PHP 的 spl_autoload_register 方法一直不被调用,什么情况?

  •  
  •   buseni · Apr 10, 2017 · 2908 views
    This topic created in 3326 days ago, the information mentioned may be changed or developed.

    define('BASEDIR', DIR); require_once BASEDIR . '/library/Load.php'; //$config = require_once "conf/config.php";//把文件读取到变量中 ini_set("include_path", ".:/usr/share/pear:/usr/share/php:/home/wwwroot/"); class LOAD { static function loadClass($class_name) { $filename = $class_name.".php"; echo $filename; if (is_file($filename)) echo BASEDIR.DIRECTORY_SEPARATOR.$filename; die(); return include_once BASEDIR.DIRECTORY_SEPARATOR.$filename; } } spl_autoload_register(array('LOAD', 'loadClass')); $server = trim($_SERVER['REQUEST_URI'], '/'); $path = explode('/', $server); switch (count($path)) { case 2: $className =DIRECTORY_SEPARATOR.'controller'.DIRECTORY_SEPARATOR. $path[0];//类名 break; } if (stripos($path[1], '?')) { $fun = substr($path[1], 0, stripos($path[1], '?'));//函数名称 } else { $fun = $path[1]; } $obj =new $className(); try { call_user_func(array($obj, $fun));//调用实例化之后对象的方法 } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; }

    windows 下是正常的,但是 linux 下,今天我买了一个 vultr 的 2.5 美元的机器,环境装上了,结果不正常,总是报错 Fatal error: Uncaught Error: Class '/controller/Home' not found in /home/wwwroot/wei/index.php:39 Stack trace: #0 {main} thrown in /home/wwwroot/wei/index.php on line 39

    感觉 spl_autoload_register 不被调用,什么情况呢?着急 今天问群友,这样告诉我的 spl_autoload_register 需要 spl 类库支持,这个类库默认是开启的

    mx1700
        1
    mx1700  
       Apr 10, 2017 via Android
    手机上看代码太乱,不想看,感觉是文件大小写问题, linux 文件系统区分大小写
    buseni
        2
    buseni  
    OP
       Apr 10, 2017 via Android
    @mx1700 V2EX 贴一个代码都是这样,唉
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3000 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 13:26 · PVG 21:26 · LAX 06:26 · JFK 09:26
    ♥ Do have faith in what you're doing.