[thelist] PHP: set_error_handler() and error suppression

Blake haswell00 at gmail.com
Fri Mar 13 20:14:01 CDT 2009


Hi List,

I'm a little confused by the behaviour I'm getting in a script. I'm
writing a class to handle the errors in my app, but my error handler
seems to get triggered even if I suppress an error. Relevant code:

<?php
	error_reporting(E_ALL);
	ini_set('display_errors', 0);
	
	set_error_handler("error::ErrorHandler");
	set_exception_handler("error::ExceptionHandler");
?>

<?php
	/**
	 * Logs the error and redirects the user
	 *
	 * @param int $severity
	 * @param string $message
	 * @param string $filename
	 * @param int $line
	 */
	public static function ErrorHandler($severity, $message, $filename, $line) {
		self::$message =
			'Severity: ' . $severity
			. ' Message: ' . $message
			. ' File: ' . $filename
			. ' Line: ' . $line;
			
		error_log(self::$message, 0);
		self::Redirect();
	}
	
	/**
	 * Attempts to send a brief description of the exception via e-mail,
then logs the exception and redirects the user
	 *
	 * @param Exception $e
	 */
	public static function ExceptionHandler($e) {
		@mail('email at address.com', 'ERROR: ' . $_SERVER['SERVER_NAME'],
$e->getMessage(), 'From: email at address.com');
		self::LogException($e);
		self::Redirect();
	}
?>

I don't have a mail server on my local so mail() should fail, but it
triggers an error even though I've used the error suppression
operator. The error is:

[Sat Mar 14 11:52:18 2009] [error] [client 127.0.0.1] Severity: 2
Message: mail() [<a href='function.mail'>function.mail</a>]: Failed to
connect to mailserver at &quot;localhost&quot; port 25, verify your
&quot;SMTP&quot; and &quot;smtp_port&quot; setting in php.ini or use
ini_set() File: ...\\error.php Line: 42

Any ideas as to why this is happening?

--
Blake Haswell
http://www.blakehaswell.com/



More information about the thelist mailing list