note 118794 added to function.trigger-error

From: Date: Sun, 07 Feb 2016 08:58:50 +0000
Subject: note 118794 added to function.trigger-error
Groups: php.notes 
Request: Send a blank email to php-notes+get-204891@lists.php.net to get a copy of this message
For those of you wanting one (or more) lines of context on your call to trigger_error, I offer this. Would be nice to use \n to get a proper stack trace, but it seems trigger_error escapes it; therefore, I use a comma. <?php /** * Behaves like trigger_error, but appends part of a stack trace to the error * message. This allows you to see where trigger_error was called from, instead * of just seeing the file and line number of the call to trigger_error. * * @param error_msg The designated error message for this error * @param error_type The designated error type for this error (E_USER_*) * @param context Number of stack frames to append, defaults to 1 * @return FALSE if wrong error_type is specified, TRUE otherwise */ function trigger_error_with_context($error_msg, $error_type, $context = 1) { $stack = debug_backtrace(); for ($i = 0; $i < $context; $i++) { if (false === ($frame = next($stack)) break; $error_msg .= ", from " . $frame['function'] . ':' . $frame['file'] . ' line ' . $frame['line']; } return trigger_error($error_msg, $error_type); } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 173.165.219.70 ---- Manual Page -- http://php.net/manual/en/function.trigger-error.php Edit -- https://master.php.net/note/edit/118794 Del: integrated -- https://master.php.net/note/delete/118794/integrated Del: useless -- https://master.php.net/note/delete/118794/useless Del: bad code -- https://master.php.net/note/delete/118794/bad+code Del: spam -- https://master.php.net/note/delete/118794/spam Del: non-english -- https://master.php.net/note/delete/118794/non-english Del: in docs -- https://master.php.net/note/delete/118794/in+docs Del: other reasons-- https://master.php.net/note/delete/118794 Reject -- https://master.php.net/note/reject/118794 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#204891) next »