note 40406 deleted from function.set-error-handler by nlopess

From: Date: Wed, 03 Mar 2004 17:44:33 +0000
Subject: note 40406 deleted from function.set-error-handler by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-66195@lists.php.net to get a copy of this message
Note Submitter: mctrafik at alex4all dot com ---- 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

« previous php.notes (#66195) next »