我检查了我的PHP ini文件(PHP.ini),并设置了display_errors,错误报告也是E_ALL。我已重新启动Apache Web服务器。
我甚至把这些行放在了脚本的顶部,它甚至不能捕捉到简单的解析错误。例如,我用“$”声明变量,而不关闭语句“;”。但我的所有脚本都显示了这些错误的空白页面,但我希望在浏览器输出中看到这些错误。
error_reporting(E_ALL);
ini_set('display_errors', 1);
还有什么要做?
我检查了我的PHP ini文件(PHP.ini),并设置了display_errors,错误报告也是E_ALL。我已重新启动Apache Web服务器。
我甚至把这些行放在了脚本的顶部,它甚至不能捕捉到简单的解析错误。例如,我用“$”声明变量,而不关闭语句“;”。但我的所有脚本都显示了这些错误的空白页面,但我希望在浏览器输出中看到这些错误。
error_reporting(E_ALL);
ini_set('display_errors', 1);
还有什么要做?
当前回答
在Unix CLI中,只将错误重定向到文件是非常实用的:
./script 2> errors.log
在脚本中,可以像往常一样使用var_dump()或等效方法(STDOUT和STDERR都将接收输出),但只能在日志文件中写入:
fwrite(STDERR, "Debug infos\n"); // Write in errors.log^
然后从另一个shell中进行实时更改:
tail -f errors.log
或者干脆
watch cat errors.log
其他回答
报告除E_NOTICE之外的所有错误
error_reporting(E_ALL & ~E_NOTICE);
显示所有PHP错误
error_reporting(E_ALL); or ini_set('error_reporting', E_ALL);
关闭所有错误报告
error_reporting(0);
已接受,包括额外选项。在我的DEVELOPMENT apache vhost(.htaccess,如果您可以确保它不会进入生产环境)的PHP文件中:
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
然而,这并不能使PHP显示解析错误-显示这些错误的唯一方法是使用以下行修改PHP.ini:
display_errors = on
(如果您没有访问php.ini的权限,那么在.htaccess中输入这一行也可以):
// I've added some extra options that set E_ALL as per https://www.php.net/manual/en/errorfunc.configuration.php.
php_flag log_errors on
php_flag display_errors on
php_flag display_startup_errors on
php_value error_reporting 2147483647
php_value error_log /var/www/mywebsite.ext/logs/php.error.log
<?php
// Turn off error reporting
error_reporting(0);
// Report runtime errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Report all errors
error_reporting(E_ALL);
// Same as error_reporting(E_ALL);
ini_set("error_reporting", E_ALL);
// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
?>
当您的站点处于活动状态时,出于安全原因,php.ini文件应该禁用display_errors。但是,对于开发环境,可以启用display_errors进行故障排除。
在Unix CLI中,只将错误重定向到文件是非常实用的:
./script 2> errors.log
在脚本中,可以像往常一样使用var_dump()或等效方法(STDOUT和STDERR都将接收输出),但只能在日志文件中写入:
fwrite(STDERR, "Debug infos\n"); // Write in errors.log^
然后从另一个shell中进行实时更改:
tail -f errors.log
或者干脆
watch cat errors.log
如果安装了Xdebug,则可以通过以下设置覆盖每个设置:
xdebug.force_display_errors = 1;
xdebug.force_error_reporting = -1;
强制显示错误类型:int,默认值:0,在Xdebug中引入>=2.3如果设置设置为1,则无论PHP的display_errors的设置是什么。强制错误报告类型:int,默认值:0,在Xdebug中引入>=2.3此设置是位掩码,如error_reporting。此位掩码将与error_reporting表示的位掩码进行逻辑“或”运算,以将错误显示到dermine。此设置只能在php.ini中进行,允许您强制显示某些错误,无论应用程序如何使用ini_set()。