Evil error reporting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Bitmaster
Forum Newbie
Posts: 20
Joined: Thu Nov 21, 2002 8:42 am

Evil error reporting

Post by Bitmaster »

I'm developing a web service in PHP using nuSOAP and, for safety and security reasons, I would like to terminate the script in case ANY kind of notice, warning or error occurs. The desired behaviour would be to log the message and kill the script.

Code: Select all

<?php

ini_set ("display_errors", "0");

function test ($i)
{
	return ($i + 1);
}

test ($problem); //Notice: undefined variable

echo ("Script execution continues..."); //Unfortunately...

?>
In this sample script, the notice is NOT logged and the script just continues its execution, and that can cause all sorts of other problems...

Is there any way to log everything (including notices) and terminate the script ?

PS: I've already looked into set_error_handler, but:

" The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called."


Thanks in advance !
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post by Syranide »

you can't use set_error_handler as those errors cannot be interpreted by scripts... because of the fact that they occur prior to execution.

therefore there is not thing you can do about such errors in scripts, the only once you can deal with are those inflicted at runtime by your code, and these can be dealt with using set_error_handler (and really there is no need to handle the other ones as they CANNOT occur by themself once your script is working, in other words, should only appear during development).
Post Reply