Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何显示Zend framework引发的异常错误?_Php_Exception_Error Handling_Zend Framework - Fatal编程技术网

Php 如何显示Zend framework引发的异常错误?

Php 如何显示Zend framework引发的异常错误?,php,exception,error-handling,zend-framework,Php,Exception,Error Handling,Zend Framework,我正在使用Zend framework,我讨厌这样一个事实:我似乎遇到了数百个异常错误,比如如果我试图引用对象的不存在属性,我的应用程序就会死机。然而,我不知道在哪里可以看到这些错误,也不知道如何在屏幕上显示它们。我已将“显示错误”设置为true,并将“错误报告”设置为E_ALL,但当抛出错误时,我看到的只是一个空白页面,仅在错误明显发生或引发异常之前呈现。引用不存在的属性在PHP中是错误,而不是异常。如果在php.ini中启用,则错误通常出现在html的输出中。但要注意:它们也可能出现在不可见

我正在使用Zend framework,我讨厌这样一个事实:我似乎遇到了数百个异常错误,比如如果我试图引用对象的不存在属性,我的应用程序就会死机。然而,我不知道在哪里可以看到这些错误,也不知道如何在屏幕上显示它们。我已将“显示错误”设置为true,并将“错误报告”设置为E_ALL,但当抛出错误时,我看到的只是一个空白页面,仅在错误明显发生或引发异常之前呈现。

引用不存在的属性在PHP中是错误,而不是异常。如果在php.ini中启用,则错误通常出现在html的输出中。但要注意:它们也可能出现在不可见的html标记中,如:

<div style="display:none"><? echo $object->nonexistant?> ...
。。。

。。。因此,您需要检查页面的HTML输出(firefox中的CTRL-U)并滚动到底部

应用程序环境变量的值是多少

ZF应用程序中的标准public/index.php执行以下操作:

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
这意味着,如果未设置应用程序_ENV,则环境将设置为“生产”。如果查看application.ini文件,您将看到,如果环境是生产环境,框架将抑制错误

当然,您正在开发,所以您希望使用“开发”环境

如果您在Apache/mod_php下运行,可以在httpd.conf或.htaccess文件中设置:

SetEnv APPLICATION_ENV development
或者,您也可能会变得丑陋,并攻击您的public/index.php:

// Define application environment

/*defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));*/

// Ugly hack because I'm too lazy to properly set up my environment.
define('APPLICATION_ENV','development');

如果使用Zend工具创建应用程序框架,通常会有一个错误控制器,用于捕获运行时错误并显示它们。您需要按照timdev的建议进行
SetEnv APPLICATION\u ENV development
,然后在应用程序/configs/APPLICATION.ini中:

[development : production]

; This section defines config parameters loaded when the APPLICATION_ENV directive
; is set to 'development' - undefined parameters are inherited from the production
; section.

; show errors and exceptions during development
 phpSettings.display_startup_errors = 1
 phpSettings.display_errors = 1
 resources.frontController.params.displayExceptions = 1

当我试图访问一个看起来不存在的对象的属性时,抛出了一个异常。考虑到所讨论的对象可能具有或可能不具有我想要检查的属性,有没有一种方法可以绕过这个问题。+1获得简单的答案并解释它的作用。它可以工作:)感谢您提到它可以在httpd.conf中设置!