我创建了这个函数来返回一个没有截断字符串的堆栈跟踪:
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%s(%s)\n",
$count,
$frame['file'],
$frame['line'],
isset($frame['class']) ? $frame['class'] : '',
isset($frame['type']) ? $frame['type'] : '', // "->" or "::"
$frame['function'],
$args
);
$count++;
}
return $rtn;
}
或者,您可以编辑 php 源,它正在截断输出:https://github.com/php/php-src/blob/master/Zend/zend_exceptions.c#L392