0

我正在尝试升级我正在从事的新项目的代码以符合 PSR-0。

我正在使用 SPL 加载器类,但是我可能做错了什么,我只是无法发现问题所在。

我不断收到以下错误:

Fatal error: Class 'widezike\General' not found in /nfs/c03/h04/mnt/169128/domains/widezike.com/html/beta/lib/functions.php on line 14

这是我的文件夹结构:

index.php
-lib
config.php
init.php
spl-class-loader.php
functions.php
    -widezike
        -General.php

这是我的函数文件,它开始与服务器端代码有关:

<?php

include 'init.php';
include 'config.php';

include 'spl-class-loader.php';

$loader = new SplClassLoader('General', 'lib/widezike');
$loader->register();

use widezike\General;

//Run the output buffer
General::ob();

所以这是我现在的代码,但我似乎找不到导致致命错误的原因......

提前致谢

4

2 回答 2

1

我在这里进行了一些猜测,但我认为问题出在构造函数中..

$loader = new SplClassLoader('General', 'lib/widezike');

在您链接到的代码中,它们是命名空间和包含路径。

我只能建议与这些一起玩,直到它起作用为止。

你可以试试:

$loader = new SplClassLoader(null, 'lib');

或者

$load = new SplClassLoad('General', 'lib');

另一方面,我个人只是使​​用一个非常简单的 spl_autoload_register 函数来为我加载类。

spl_autoload_register(function($class){

    $filename = str_replace('\\', '/', $class) . '.php';
    require($filename);

});

$object = new phutureproof\common\whatever();

然后我会有一个/phutureproof/common/whatever.php包含以下内容的文件:

<?php
namespace phutureproof\common;

class whatever
{

}
于 2013-06-05T12:02:55.757 回答
0

我意识到问题在于我的命名空间是错误的,所以如果你有同样的问题,只需检查并确保你的命名空间是正确的!

于 2013-06-05T12:37:53.203 回答