禁用自动加载器尝试加载 JsonSerializable

Disable autoloader from trying to load JsonSerializable

我在 CodeIgniter 的库中进行了以下设置:

class DataModelAutoloader
{
    public function __construct()
    {
        spl_autoload_register(array($this, 'loader'));
        log_message('debug', 'QR-Invited autoloader initialized');
    }

    public function loader($className)
    {
        log_message("debug", "Accessing loader for class: " . $className);
        if (substr($className, 0, 9) == 'datamodel') {
            $fullyQualifiedPath = APPPATH.str_replace('\', DIRECTORY_SEPARATOR, $className).'.php';
            log_message('debug', 'Fully qualified path is: ' . $fullyQualifiedPath);
            require APPPATH.str_replace('\', DIRECTORY_SEPARATOR, $className).'.php';
        }
    }
}

现在,datamodel/Invite.php 中我的数据模型之一 Invite 正在加载,但它被定义为:

class Invite implements JsonSerializable {
  ...
};

问题是它现在正在尝试加载 datamodel/JsonSerializable.php,这当然不存在,因为我想使用内置的 PHP 5.4.0 JsonSerializable。 (我 PHP 5.5.X 安装在我正在 运行 的盒子上)。所以,当我 运行 这段代码时,我得到以下异常:

<p>Severity: Warning</p>
<p>Message:  require(qrinvited-application/datamodel/JsonSerializable.php): failed to open stream: No such file or directory</p>
<p>Filename: libraries/Datamodelautoloader.php</p>
<p>Line Number: 20</p>

有没有办法禁用尝试自动加载像这样应该内置到 PHP5 中的东西?或者,也许我在扩展 class?

时做错了什么

如果全部关于 'namespaces',请使用 implements \JsonSerializable\ 使得 PHP 知道使用 default 命名空间而不是 class 当前所在的命名空间(在本例中为 datamodel)。