PHP异常堆栈跟踪中缺少函数参数

10
我正在努力为我的php应用程序进化自己的错误处理程序,并且我需要在开发服务器上向用户发送一个漂亮的异常报告。所以,当它捕获到一个异常时,它必须解析异常堆栈跟踪以显示函数、行参数等。但是,在函数调用中,我不再有参数。我认为这是由于XDebug引起的,我尝试更改xdebug.collect_params的值来修复它,但没有任何成功。实际上,这个配置只改变了xdebug默认报告的显示,现在它有了函数调用的参数。我制作了一个测试脚本来测试它,所以我让你看一下。
<?php
$config = 'xdebug.collect_params';
echo "Current value of $config is<br />\n";
var_dump(ini_get($config));

ini_set($config, 3);

function fallDeepToHell($param) {
    echo 'Param is : ' . $param . "<br>\n";
    throw new Exception();
}

try {
    fallDeepToHell('from heaven');
} catch(Exception $e) {
    var_dump($e->getTrace());
    var_dump($e->getTraceAsString());
}
fallDeepToHell('from heaven');

我的开发服务器上的结果为:

在此输入图片描述

我正在使用 PHP 7.4 和 FPM。

我的 php.ini 更改如下:

max_execution_time = 30
memory_limit = 128M
error_reporting = E_ALL
display_errors = On
display_startup_errors = On
html_errors = On
post_max_size = 100M
upload_max_filesize = 49M
date.timezone = Europe/Paris

;[mail function]
mail.add_x_header = On

;[Session]
session.gc_divisor = 1000
session.gc_maxlifetime = 43200

我的XDebug设置只涉及远程事务。


在最后调用 fallDeepToHell('from heaven'); 时没有使用 try / catch 块。这会抛出一个未被捕获的异常。最好从下往上阅读回溯信息。你可以看到它是由第22行触发的,而该行是从 main() 中调用的。 - Markus Zeller
@Derick 我正在使用 Xdebug v2.9.1 和 PHP FPM 7.4。 - Loenix
1
我再次尝试了这些版本,但它可以工作。你介意分享一下你的phpinfo()输出吗?或者,如果可能的话,提供一个Docker设置,显示这个错误行为? - Derick
这是我的phpinfo的HTML https://pastebin.com/HtRtaqnJ - Loenix
以下是我的php.ini更改: max_execution_time = 30 memory_limit = 128M error_reporting = E_ALL display_errors = On display_startup_errors = On html_errors = On post_max_size = 100M upload_max_filesize = 49M date.timezone = Europe/Paris;[mail function] mail.add_x_header = On;[Session] session.gc_divisor = 1000 session.gc_maxlifetime = 43200 - Loenix
显示剩余2条评论
1个回答

19
我曾经也遇到过同样的问题,后来发现是在PHP 7.4中引入了新的zend.exception_ignore_args INI指令。

zend.exception_ignore_args是一个新的INI指令,用于包含或排除从异常生成的堆栈跟踪中的参数。


我将这个指令设置为关闭,现在它可以正常工作了!谢谢! - Loenix
它声称在PHP中默认为“off”/“0”,但在php.ini中再次将值设置为“0”确实解决了我的问题。对我来说,这是在使用sentry-php时发生的,并且解决了未将参数/变量发送到Sentry的问题。 - forrestmid
1
懒人用的代码行:ini_set('zend.exception_ignore_args', 0); - Paul

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接