Php Spl_自动加载_寄存器无法打开流

Php Spl_自动加载_寄存器无法打开流,php,class,include,autoload,spl-autoload-register,Php,Class,Include,Autoload,Spl Autoload Register,这是Server/Init.php: spl_autoload_register(function($file) { include str_replace('\\, '/', $file) . '.php'; }); $GLOBALS['config'] = $config; $GLOBALS['patched'] = $patched; $GLOBALS['crumbs'] = $crumbs; $utils = new Utils(); $mysql = new MySQL

这是Server/Init.php:

spl_autoload_register(function($file) {
    include str_replace('\\, '/', $file) . '.php';
});

$GLOBALS['config']  = $config;
$GLOBALS['patched'] = $patched;
$GLOBALS['crumbs']  = $crumbs;

$utils = new Utils();
$mysql = new MySQL();
$GLOBALS['utils'] = $utils;
$GLOBALS['mysql'] = $mysql;
问题似乎在于试图包含Utils.php,它位于classes文件夹中。以下是错误:

Warning: include(Utils.php): Failed to open stream: No such file or directory in C:/xampp/htdocs/server/Init.php on line 9

Warning: include(): Failed opening 'Utils.php' for inclusion (include_path='.;C:/xampp/php/PEAR') in C:/xampp/htdocs/server/Init.php on line 9

Fatal error: Class 'Utils' not found in C:/xampp/htdocs/server/Init.php on line 16
如果有帮助,这是Server/Classes/Utils.php:

class Utils {

    public function writeRawOutput($str) {
        echo $str;
    }

    public function writeOutput($msg, $type = null, $pref = null) {
        $msg = strval($msg);
        if($type == null && $pref == null)
            echo "$msg \r\n";
        elseif($type == null && $pref != null)
            echo "[$pref] > $msg \r\n";
        elseif($type != null && $pref == null)
            echo "[$type] > $msg \r\n";
        elseif($type != null && $pref != null)
            echo "[$pref] [$type] > $msg \r\n";
    }

    public function getInput($str) {
        $this->writeOutput($str);
        $input = trim(fgets(STDIN));
        return $input;
    }

    public function getConfig($path = null) {
        if($path) {

            $config = $GLOBALS['config'];
            $path   = explode('/', $path);

            foreach($path as $bit) {
                if(isset($config[$bit])) {
                    $config = $config[$bit];
                }
            }

            return $config;
        }
        return false;
    }

}

我做错了什么?如何修复此问题?

1您发布的Init.php有语法错误。我假设真实文件的情况并非如此。2如果Init.php位于“main”目录中,并且类可以在“/classes/”子目录中找到,则包括“\uu DIR\uu.”/classes/”。str\u替换“\\”、“/”、$file.”。php′;服务器目录中有Init.php和一个名为Classes的文件夹,其中包含Utils.php。