【问题标题】:Kohana error "Call to a member function add() on a non-object" on Kohana::$logKohana 错误“在非对象上调用成员函数 add()”::$log
【发布时间】:2012-08-17 22:21:33
【问题描述】:

我在 Kohana::$log 上收到错误“调用非对象上的成员函数 add()”

application/logs目录没有登录。我描述的错误在 apache error_log 上找到。它是这样出现的

[Fri Aug 17 17:07:09 2012] [error] [client MY.IPA.DDR.ESS] PHP 致命错误:在 /var/www/ 中的非对象上调用成员函数 add()第 8 行的 html/application/classes/kohana/exception.php

这是我的错误控制器。

<?php
class Kohana_Exception extends Kohana_Kohana_Exception {
    public static function handler(Exception $e) {
        if (Kohana::DEVELOPMENT === Kohana::$environment) {
            parent::handler($e);
        } else {
            try {
                Kohana::$log->add(Log::ERROR, "own exception handler");
                Kohana::$log->add(Log::ERROR, parent::text($e));
                $attributes = array('action' => 500, 'message' => rawurlencode($e->getMessage()));
                if ($e instanceof HTTP_Exception) {
                    $attributes['action'] = $e->getCode();
                }
                // Error sub-request.
                echo Request::factory(Route::get('error')->uri($attributes))->execute()->send_headers()->body();
            }
            catch(Exception $e) {
                // Clean the output buffer if one exists
                ob_get_level() and ob_clean();
                // Display the exception text
                echo parent::text($e);
                // Exit with an error status
                exit(1);
            }
        }
    }
}

从代码看来Kohana::$log 尚未初始化。但是这段代码工作了很长时间。现在是什么让它不起作用?

我在 Fedora 15 上使用 Kohana-3.2PHP 5.3.13

【问题讨论】:

  • 5 个月后,我在同一个文件上遇到了同样的错误!我在谷歌上搜索导致了我自己的问题:o

标签: php error-handling kohana fatal-error


【解决方案1】:

我已经解决了这个问题。如果任何其他 kohana 开发人员出现此问题,并且他从谷歌来到这里,这里就是解决方案。

从 root shell 运行以下命令。请记住,如果您重新启动服务器,您将不得不再次运行它。

setsebool -P httpd_unified 1

附加信息:如何追踪。

检查这些位置

  1. Apache 错误日志
  2. 应用程序目录中的 Kohana 日志(如果您为调试而登录)
  3. 检查/var/log/messages

如果它的 SElinux 问题,您会在 /var/log/messages 上找到日志条目。这就是我得到的。

setroubleshoot:SELinux 正在阻止 /usr/sbin/httpd 对目录 /var/www/html/application/cache 进行写访问。获取完整的 SELinux 消息。运行 sealert -l 087dfdb5-c7de-4238-8e6b-a713213a456d

如前所述,运行 sealert -l 087dfdb5-c7de-4238-8e6b-a713213a456d 将显示我作为解决方案编写的命令。

【讨论】:

    【解决方案2】:

    试试看:

    Log::instance()->add(Log::ERROR, "own exception handler");
    

    有效。当前的 Kohana 文档似乎表明使用 $log 应该仍然有效,但在异常处理之前它可能会在某处未设置。但是,从 Log 类中检索实例应该随时可用。

    【讨论】:

    • 发现问题。它的 SELinux 正在阻止写入缓存。把它写成答案。
    【解决方案3】:

    您可能有权限问题。就我而言,是 httpd 服务 (apache2) 无法访问项目文件。 这是一个残酷的解决方案(只有在您的安全情况允许时才这样做):

    $ sudo chmod -R 0777 /var/www/html/mysite/

    来自: move_uploaded_file gives "failed to open stream: Permission denied " error after all configurations i did

    【讨论】:

    • 小心chmod -R 0777:这通常是错误的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多