note 68642 added to ref.errorfunc

From: Date: Fri, 04 Aug 2006 15:40:04 +0000
Subject: note 68642 added to ref.errorfunc
Groups: php.notes 
Request: Send a blank email to php-notes+get-115552@lists.php.net to get a copy of this message
It is totally possible to use debug_backtrace() inside an error handling function. Here, take a look: <?php set_error_handler('errorHandler'); function errorHandler( $errno, $errstr, $errfile, $errline, $errcontext) { echo 'Into '.__FUNCTION__.'() at line '.__LINE__. "\n\n---ERRNO---\n". print_r( $errno, true). "\n\n---ERRSTR---\n". print_r( $errstr, true). "\n\n---ERRFILE---\n". print_r( $errfile, true). "\n\n---ERRLINE---\n". print_r( $errline, true). "\n\n---ERRCONTEXT---\n".print_r( $errcontext, true). "\n\nBacktrace of errorHandler()\n". print_r( debug_backtrace(), true); } function a( ) { //echo "a()'s backtrace\n".print_r( debug_backtrace(), true); asdfasdf; // oops } function b() { //echo "b()'s backtrace\n".print_r( debug_backtrace(), true); a(); } b(); ?> Outputs: <raw> Into errorhandler() at line 9 ---ERRNO--- 8 ---ERRSTR--- Use of undefined constant asdfasdf - assumed 'asdfasdf' ---ERRFILE--- /home/theotek/test-1.php ---ERRLINE--- 23 ---ERRCONTEXT--- Array ( ) Backtrace of errorHandler() Array ( [0] => Array ( [function] => errorhandler [args] => Array ( [0] => 8 [1] => Use of undefined constant asdfasdf - assumed 'asdfasdf' [2] => /home/theotek/test-1.php [3] => 23 [4] => Array ( ) ) ) [1] => Array ( [file] => /home/theotek/test-1.php [line] => 23 [function] => a ) [2] => Array ( [file] => /home/theotek/test-1.php [line] => 30 [function] => a [args] => Array ( ) ) [3] => Array ( [file] => /home/theotek/test-1.php [line] => 33 [function] => b [args] => Array ( ) ) ) </raw> So, the first member of the backtrace's array is not really surprising, except from the missing "file" and "line" members. The second member of the backtrace seem the be a hook inside the zend engine that is used to trigger the error. Other members are the normal backtrace. ---- Server IP: 66.207.199.35 Probable Submitter: 24.200.182.31 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/ref.errorfunc.php Edit -- https://master.php.net/note/edit/68642 Del: integrated -- https://master.php.net/note/delete/68642/integrated Del: useless -- https://master.php.net/note/delete/68642/useless Del: bad code -- https://master.php.net/note/delete/68642/bad+code Del: spam -- https://master.php.net/note/delete/68642/spam Del: non-english -- https://master.php.net/note/delete/68642/non-english Del: in docs -- https://master.php.net/note/delete/68642/in+docs Del: other reasons-- https://master.php.net/note/delete/68642 Reject -- https://master.php.net/note/reject/68642 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#115552) next »