如何获取PHP的完整字符串getTraceAsString()?

编程入门 行业动态 更新时间:2024-10-28 08:20:58
本文介绍了如何获取PHP的完整字符串getTraceAsString()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 getTraceAsString()获取堆栈跟踪,但由于某些原因字符串被截断。

I'm using getTraceAsString() to get a stack trace but the string is being truncated for some reason.

示例,抛出异常,并使用以下方式记录字符串:

Example, an exception is thrown and I log the string using:

catch (SoapFault $e) { error_log( $e->getTraceAsString() ) }

打印的字符串out是:

The string thats prints out is:

#0 C:\Somedirectory\Somedirectory\Somedirectory\Somedir\SomeScript.php(10): SoapClient-> SoapClient(' http://www.ex ...')

如何获得完整的字符串打印?

How can I get the full string to print?

推荐答案

我创建此函数以返回没有截断字符串的堆栈跟踪:

I created this function to return a stack trace with no truncated strings:

function getExceptionTraceAsString($exception) { $rtn = ""; $count = 0; foreach ($exception->getTrace() as $frame) { $args = ""; if (isset($frame['args'])) { $args = array(); foreach ($frame['args'] as $arg) { if (is_string($arg)) { $args[] = "'" . $arg . "'"; } elseif (is_array($arg)) { $args[] = "Array"; } elseif (is_null($arg)) { $args[] = 'NULL'; } elseif (is_bool($arg)) { $args[] = ($arg) ? "true" : "false"; } elseif (is_object($arg)) { $args[] = get_class($arg); } elseif (is_resource($arg)) { $args[] = get_resource_type($arg); } else { $args[] = $arg; } } $args = join(", ", $args); } $rtn .= sprintf( "#%s %s(%s): %s(%s)\n", $count, $frame['file'], $frame['line'], $frame['function'], $args ); $count++; } return $rtn; }

或者,您可以编辑截断输出的php源: a href =github/php/php-src/blob/master/Zend/zend_exceptions.c#L392 =noreferrer> github/php/php-src/ blob / master / Zend / zend_exceptions.c#L392

Alternatively, you could edit the php source where it is truncating the output: github/php/php-src/blob/master/Zend/zend_exceptions.c#L392

更多推荐

如何获取PHP的完整字符串getTraceAsString()?

本文发布于:2023-11-22 08:43:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616736.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   完整   PHP   getTraceAsString

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!