-
Notifications
You must be signed in to change notification settings - Fork 1
/
getTraceAsString.php
44 lines (44 loc) · 1.55 KB
/
getTraceAsString.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
* The default Exception::getTraceAsString() truncates the method parameters
* It cannot be overwritten because it is final
*
* This method duplicates the Exception::getTraceAsString() functionality, but without truncating the parameters.
* Pass the exception object and enjoy.
*/
function getExceptionTraceAsString(Exception $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;
}