note 102183 deleted from exception.gettrace by danbrown
| From: | danbrown@php.net | Date: | Tue, 01 Feb 2011 14:00:27 +0000 |
| Subject: | note 102183 deleted from exception.gettrace by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176559@lists.php.net to get a copy of this message | ||
Note Submitter: Trejder
----
Code provided by andreas has some minor flaws:
1. It display information about only last (topmost) stack trace line (maybe wanted feature).
2. It does not checks whether $trace[0]['class'] is set. Doing only
if($trace[0]['class'] != '') will fail in strict-error reporting PHP mode.
3. It does not displays information about file and line of file, where stacked call occurred.
I propose slightly modified version of his function:
private static function GetFormattedStackTrace(Exception $e)
{
$result = '<div class="flash-notice">';
$traces = $e->getTrace();
$n = count($traces);
foreach($traces as $trace)
{
--$n;
$result.= ($n > 0) ? '<div style="padding-bottom:
7px">'.($n) : '#';
$result.= '. Function<strong>';
if(isset($trace['class']) && ($trace['class'] !=
''))
{
$result .= $trace['class'];
$result .= $trace['type'];
}
$result .= $trace['function'].'()</strong>';
if(isset($trace['line']) && ($trace['line'] !=
''))
{
$result .= ' [line <strong>';
$result .= $trace['line'];
$result .= '</strong> in file <em>';
$result .= $trace['file'].'</em>]';
}
$result .= ($n > 0) ? '</div>' : '';
}
$result.= '</div>';
return $result;
}