Change and restore ErrorHandling (QF Rule using HTTP_Client)

From: Date: Thu, 21 Oct 2004 16:30:15 +0000
Subject: Change and restore ErrorHandling (QF Rule using HTTP_Client)
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-15027@lists.php.net to get a copy of this message
Hi, normally I use: PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handle_pear_error'); for setting an error handler resposible for all PEAR Packages. Within a QF-Rule validating URL's, I use HTTP_Client to perform an HEAD- Request. This raise an Error if the $uri couldn't connected and therefore if have to change the error handling to PEAR_ERROR_RETURN to catch this. Unfortunally PEAR::setErrorHandling() don't return the old state like some PHP functions usualy do (error_reporting, setlocale,...). Is there a solution to prevent my validate method from knowing the old state? function validate($value, $options) { $uri = 'http://' . $value; require_once 'HTTP/Client.php'; $client = new HTTP_Client(); // change error handling for request PEAR::setErrorHandling(PEAR_ERROR_RETURN); if (PEAR::isError($client->head($uri))) { $return = false; } else { $result = $client->currentResponse(); print_d($result['code'], 'Result of head request'); if ($result['code'] == 404 || $result['code'] == 403) { $return = false; } else { $return = $result['code']; } } // restore original error handling PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handle_pear_error'); return $return; } Thanks, ThS.

« previous php.pear.general (#15027) next »