note 102183 added to exception.gettrace

From: Date: Tue, 01 Feb 2011 13:51:23 +0000
Subject: note 102183 added to exception.gettrace
Groups: php.notes 
Request: Send a blank email to php-notes+get-176555@lists.php.net to get a copy of this message
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; } ---- Server IP: 82.177.164.100 Probable Submitter: 85.14.84.74 ---- Manual Page -- http://www.php.net/manual/en/exception.gettrace.php Edit -- https://master.php.net/note/edit/102183 Del: integrated -- https://master.php.net/note/delete/102183/integrated Del: useless -- https://master.php.net/note/delete/102183/useless Del: bad code -- https://master.php.net/note/delete/102183/bad+code Del: spam -- https://master.php.net/note/delete/102183/spam Del: non-english -- https://master.php.net/note/delete/102183/non-english Del: in docs -- https://master.php.net/note/delete/102183/in+docs Del: other reasons-- https://master.php.net/note/delete/102183 Reject -- https://master.php.net/note/reject/102183 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#176555) next »