RE: [PHP] Fatal Errors and Error Handling

From: Date: Tue, 24 Apr 2001 14:48:42 +0000
Subject: RE: [PHP] Fatal Errors and Error Handling
Groups: php.general 
Request: Send a blank email to php-general+get-50093@lists.php.net to get a copy of this message
> > > standard we are > > > if (@foo_bar (42, 4711) == ERROR_CODE) { > > > PrintXMLErrorMessage (); > > I do not believe the above will work. When using the "@" symbol > > in front of an expression, it makes it so that the error > > code that is returned is "0". While writing my error handler class, > > in the > Wrong. From > http://php.net/manual/en/language.operators.errorcontrol.php : > ------ > PHP supports one error control operator: the at sign (@). When prepended > to an expression in PHP, any error messages that might be generated by > that expression will be ignored. > ------ > The @ operator suppresses any error *message*, but leaves the return > value intact. Just imagine that with your interpretation in the following > snippet > $conn = @mysql_connect(...) > $conn would always be set to 0... Wrong back. From: http://php.net/manual/en/function.set-error-handler.php ---- It is important to remember that the standard PHP error handler is completely bypassed. error_reporting() settings will have no effect and your error handler will be called regardless - however you are still able to read the current value of error_reporting() and act appropriately. Of particular note is that this value will be 0 if the statement that caused the error was prepended by the @ error-control operator. ---- Using your example, $conn wouldn't be '0' but if any error that is generated by mysql_connect, that error code/number (what you are going to be looking for) will be '0'. So if, in the original function f00_bar(), it tried to return any error code/number, that code/number would be '0' (zero) by nature of having the "@" operator prepended to the function call. You don't have to believe me. Set up your own error handler and see for yourself what error number you get when the "@" symbol is prepended to an expression. Chris

« previous php.general (#50093) next »