note 40406 added to function.set-error-handler

From: Date: Wed, 03 Mar 2004 04:53:17 +0000
Subject: note 40406 added to function.set-error-handler
Groups: php.notes 
Request: Send a blank email to php-notes+get-66139@lists.php.net to get a copy of this message
So this function has no effect on fatal and parse errors, which makes a very big deal if you're using an output buffer. No matter if there is a fatal or parse error, output still comes out, which might cause a very nasty error with xml parser, if there's a <?xml .. blab la?> tag, which is becoming a web standart, but in any other way, if there is an error, you don't want your script to output a damaged page. I'd just like to point out that in your custom error function you have to add ob_end_clean() and clean out the buffer in your callback function. For Example <?php function Error_Handler($type, $message, $file, $line, $c) { ob_end_clean(); //...all your stuff exit($message) //if you have one, or just put die(); } function Output_Buffer($buffer) { //cleaning spaces and returns in the beginning of the file $buffer = eregi_replace("^[\r\t\n ]+", '', $buffer); if(ereg("^<br />", $buffer)) { $buffer = eregi_replace("<!.+", '', $buffer); } } set_error_handler("Error_Handler"); ob_start("Output_Buffer"); echo "<!DOCTYPE ...."; //..bla.. //error happens //..bla.. ob_end_flush(); ?> You can substitute "^<br />" to whatever your server's error handling output starts with, and "<!.+" to whatever your page starts with(in my case it's <!DOCTYPE, might also be <?xml or <html) Hope it helps ---- Manual Page -- http://www.php.net/manual/en/function.set-error-handler.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40406 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40406&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40406&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#66139) next »