note 60224 added to function.set-error-handler

From: Date: Fri, 30 Dec 2005 12:47:12 +0000
Subject: note 60224 added to function.set-error-handler
Groups: php.notes 
Request: Send a blank email to php-notes+get-100987@lists.php.net to get a copy of this message
If you are debugging json or ajax applications, you may find the following error handler usefull. It should be used for php generated javascript files only. The html-tags are just meant to be a display hint for a webbrowser when it does not know it is displaying javascript. Please understand that the error message is only shown by the browsers js interpreter, if the instruction flow passes the position of the error. If you don't have php-json (you should get it from http://www.aurore.net/projects/php-json/) remove the line with 'json_encode' or use an encoder of your own choice. <?php function myErrorHandler($errno, $errstr, $errfile, $errline, $context) { $a = "/*<b>PHP Error Handler:</b><pre>*/\nalert('PHP"; $e = "\\n".addslashes($errstr).'\\n'; $e.= " =>In line $errline of file ".addslashes($errfile)."');\n"; $e.= 'alert (\'Context:'.str_replace ('\\n',"\\n'+\n'",json_encode (print_r ($context,true)))."');\n"; $e.= "debugger;<*</pre>*/"; switch ($errno) { case E_ERROR: echo "$a ERROR: $e"; exit(1); case E_WARNING: echo "$a WARNING: $e"; exit(1); case E_NOTICE: echo "$a NOTICE: $e"; break; default: echo "$a OTHER($errno): $e"; } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.set-error-handler.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60224 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60224&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60224&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60224&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60224&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60224&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60224&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60224&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60224&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#100987) next »