php 不显示解析错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/941766/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 00:24:13  来源:igfitidea点击:

Parse errors are not displayed

phpiis-6error-reporting

提问by temuri

I want PHP to display parse errors on screen. What I get instead is a blank page. Nothing gets written to server's error log file.

我希望 PHP 在屏幕上显示解析错误。我得到的是一个空白页。没有任何内容写入服务器的错误日志文件。

My setup: PHP5.2.9/IIS 6(not Apache!).

我的设置:PHP5.2.9/ IIS 6(不是 Apache!)。

My PHP.INI:

我的 PHP.INI:

error_reporting=E_STRICT
display_errors = On
display_startup_errors = On
log_errors = On
error_log = "C:\Program Files\Zend\ZendServer\logs\php_error.log"

How do I get parse or fatal errors to be either logged or shown on screen?

如何在屏幕上记录或显示解析或致命错误?

Thanks, Temuri

谢谢,手鞠

UPDATE: After playing with different switches it looks to be an IIS specific problem. ANY IDEAS FOLKS?

更新:使用不同的开关后,它看起来是 IIS 特定的问题。大家有什么想法吗?

回答by temuri

Setting error level in php file itself does not resolve the problem here because the file itself cannot be parsed !!

在 php 文件本身中设置错误级别并不能解决这里的问题,因为文件本身无法解析!!

You need to change error_reporting line in your php.ini as follows:

您需要更改 php.ini 中的 error_reporting 行,如下所示:

error_reporting = E_ALL

BTW: There are some examples in php.ini file about what to do to display which type of error messages.

顺便说一句:php.ini 文件中有一些关于如何显示哪种类型的错误消息的示例。

Good luck,

祝你好运,

mcemoz

麦克莫兹

回答by Chris Tonkinson

Apache doesn't always like to report parsing errors either. From the command line, run

Apache 也不总是喜欢报告解析错误。从命令行,运行

php -l <file>

The -l switch tells PHP to check file syntax. See the man page.

-l 开关告诉 PHP 检查文件语法。请参阅手册页。

回答by James Socol

E_STRICTis not included in E_ALL(until PHP 6). If you want to keep getting E_STRICT

E_STRICT不包含在E_ALL(直到 PHP 6)中。如果你想继续获得E_STRICT

In php.ini:

在 php.ini 中:

error_reporting = E_ALL | E_STRICT

At runtime:

在运行时:

error_reporting( E_ALL | E_STRICT );

You'll need to set the error reporting level (and display_errors) in php.ini to see syntax errors. If PHP encounters a syntax error, the runtime doesn't get executed, so setting at runtime won't work. (See the display_errorslink.)

您需要在 php.ini 中设置错误报告级别(和display_errors)以查看语法错误。如果 PHP 遇到语法错误,则不会执行运行时,因此在运行时设置将不起作用。(见display_errors链接。)

回答by jchook

You can verify the script syntax with this command in terminal:

您可以在终端中使用以下命令验证脚本语法:

php -l path/to/file.php

Personally, I added this line to my ~/.bash_profilefile so I can easily run php -lon all files in the current working directory:

就个人而言,我将此行添加到我的~/.bash_profile文件中,以便我可以轻松地php -l在当前工作目录中的所有文件上运行:

phpl() { for i in *.php; do php -l $i; done }

If you're really hardcore, you can even run your app from the command line. You'll have a much better chance of seeing compile-time errors, and it's just kinda cool.

如果你真的很铁杆,你甚至可以从命令行运行你的应用程序。您将有更好的机会看到编译时错误,这很酷。

You can use the $argv variable to get the first argument, $argv[1], then use that as the request.

您可以使用 $argv 变量获取第一个参数 $argv[1],然后将其用作请求。

<?php
// show those errors!
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);

// simulate a web server request
$request = '/' . isset($argv[1]) ? ltrim($argv[1], '/') : '/';
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'] = $request;

Then you can run your script via command line. This would be the equivalent of visiting: your-webapp.com/request/uri/here

然后你可以通过命令行运行你的脚本。这相当于访问: your-webapp.com/request/uri/here

php /path/to/script.php request/uri/here

Here is a more comprehensive example for running CodeIgniter via command line. It should work for many other frameworks too: http://phpstarter.net/2008/12/run-codeigniter-from-the-command-line-ssh/

这是通过命令行运行 CodeIgniter 的更全面的示例。它也适用于许多其他框架:http: //phpstarter.net/2008/12/run-codeigniter-from-the-command-line-ssh/

回答by Vasili Pascal

As Rasmus Lerdorf suggests, always use error_reporting(-1) on development server.

正如 Rasmus Lerdorf 建议的那样,始终在开发服务器上使用 error_reporting(-1)。

回答by Ralph Frost

Re: Blank screen of php death death, I discovered that setting

回复:php死死的黑屏,我发现了那个设置

php_value error_reporting "E_ALL" or php_value error_reporting 8192

php_value error_reporting "E_ALL" 或 php_value error_reporting 8192

in .htaccess on my Windows 7, Wampserver w/ apache 2.2.4 and php 5.3.13 are sure ways to get the blank php error screen -- today, June 3, 2014. These htaccess lines DO set the desires value in phpinfo(), but the display of the errors happens only when the line is commented out (not used) in htaccess.

在我的 Windows 7 上的 .htaccess 中,Wampserver w/ apache 2.2.4 和 php 5.3.13 是获得空白 php 错误屏幕的确定方法——今天,2014 年 6 月 3 日。这些 htaccess 行确实在 phpinfo( ),但只有在 htaccess 中注释掉(未使用)该行时才会显示错误。

BUT... the next minute I discover that

但是……下一分钟我发现

php_value error_reporting 8191

php_value error_reporting 8191

DOES set the phpinfo() value AND also allows display of the error messages to the browser! D'oh! It must be an integer and also apparently a particular or valid integer, and not just a large enough integer!

确实设置了 phpinfo() 值并且还允许向浏览器显示错误消息!哦!它必须是一个整数,而且显然是一个特定的或有效的整数,而不仅仅是一个足够大的整数!

回答by Travis

If you're using Zend Framework (v1) and you're using the Autoloader, the following code will prevent parse errors from being displayed:

如果您使用 Zend Framework (v1) 并且使用 Autoloader,以下代码将防止显示解析错误:

self::$Autoloader->suppressNotFoundWarnings(true);

self::$Autoloader->suppressNotFoundWarnings(true);

See the following answer for more details:

有关更多详细信息,请参阅以下答案:

Display php errors when using Zend framework

使用 Zend 框架时显示 php 错误

回答by Garrett

Try this.

尝试这个。

error_reporting(E_ALL);
ini_set("display_errors", 1);