PHP的Nesting level too deep报错

在程序里增加日志记录debugtrace信息,以便排查问题,代码如下:

$traceInfo = debug_backtrace();
$logTrace = array();
array_shift($traceInfo);
array_shift($traceInfo);
$logTrace[] = array_shift($traceInfo);
$logTrace[] = array_shift($traceInfo);

file_put_contents('/tmp/test.log', var_export($logTrace, true));

但是在PHP的错误日志里却发现很多"Nesting level too deep"的报错,遂百度之。

If you are using the backtrace function in an error handler, avoid using var_export() on the args, as you will cause fatal errors in some situations, preventing you from seeing your stack trace. Some structures will cause PHP to generate the fatal error "Nesting level too deep - recursive dependency?" This is a design feature of php, not a bug (see http://bugs.php.net/bug.php?id=30471)

修改代码,使用json_encode处理数组记录日志,错误没有了。

标签: none

添加新评论