【问题标题】:Fatal error: class not found, but is loaded致命错误:找不到类,但已加载
【发布时间】:2012-11-18 18:23:44
【问题描述】:

我正在尝试在实时服务器上运行我的脚本,但它正在暂存。

在本地,一切都很好(OS X),远程,CentOS/Nginx,我遇到了一个致命问题..脚本说我的自定义数据库类找不到。

查看加载的内容,使用get_declared_classes(),我绝对可以看到我的自定义数据库类,它在调用它的脚本/类之前加载。

它正在通过我的自动加载器加载:

spl_autoload_register(function ($className) {
if (file_exists(ROOT . DS . 'library' . DS . 'intranet' .DS . 'classes' . DS .strtolower($className) . '.php')){
    require_once(ROOT . DS . 'library' . DS . 'intranet' .DS . 'classes' . DS .strtolower($className) . '.php');
} else if (file_exists(ROOT . DS . 'application' . DS . 'controller' . DS . strtolower($className) . '.php')) {
    require_once(ROOT . DS . 'application' . DS . 'controller' . DS . strtolower($className) . '.php');
} else if (file_exists(ROOT . DS . 'application' . DS . 'model' . DS . strtolower($className) . '.php')) {
    require_once(ROOT . DS . 'application' . DS . 'model' . DS . strtolower($className) . '.php');
} else if (file_exists(ROOT . DS . 'application' . DS . 'view' . DS . strtolower($className) . '.php')) {
    require_once(ROOT . DS . 'application' . DS . 'view' . DS . strtolower($className) . '.php');
} else {
    throw new Exception("Class: $className not autoloaded!");
}
});

没有抛出异常。

Array ( [128] => Router 
        [129] => debug 
        [130] => database 
        [131] => SessionManager 
        [132] => security 
) 

Fatal error: Class 'database' not found in 
/home/nginx/domains/ckrisc/public/library/intranet/classes/sessionmanager.php 
on line 76

引导和文件包含如下:

require_once (ROOT . DS . 'config'  . DS . 'config.php'                         );
require_once (ROOT . DS . 'config'  . DS . 'directories.config.php'             );
require_once (library . DS . 'setup.php'        );
require_once (library . DS . 'Autoloader.php'   );
require_once (library . DS . 'Router.php'       );
require_once (library . DS . 'init.php'         );

在这种情况下,类database 正在从会话管理器中调用,该会话管理器在init.php 中调用。

脚本在这里失败:

$sessionId = database::getInstance()->real_escape_string($sessionId);

关于我在这里缺少什么的任何想法?

【问题讨论】:

  • 在异常之前调用get_declared_classes()。检查回溯
  • @KarolyHorvath,我做到了,它已经被加载了。
  • 它是字面上的异常吗?
  • @KarolyHorvath,是的,我把它放在调用数据库类之前。我什至后来放了它,它仍然在那里。
  • 你说它抛出异常之后是什么意思...

标签: php


【解决方案1】:

也许您在声明自动加载函数之前调用了该类。

【讨论】:

  • 在我的开发环境中不会发生同样的情况吗?在配置和错误报告之后直接调用自动加载器。
  • 我提到了这种可能性,因为似乎 database 是那些必须在任何其他进程之前调用的类之一。
  • 是的,这是第三个加载的类,请参阅我帖子中的数组。
  • 这意味着类没有被加载。除其他可能性外,异常可能不起作用。
  • 这让我明白为什么它没有被加载;它根本没有遇到异常。
【解决方案2】:

事实证明 APC 3.1.13 引起了一些问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-20
    • 2014-10-03
    • 1970-01-01
    • 2017-06-14
    • 2013-10-18
    • 2011-09-08
    • 2011-12-17
    • 2018-12-21
    相关资源
    最近更新 更多