I am trying to get twitter updates like this:
try {
$doc = new DOMDocument();
$doc->load('http://twitter.com/statuses/user_timeline/1234567890.rss');
$isOK = true;
} catch( Zend_Exception $e ) {
$isOK = false;
}
If there is not problem with internet connection then $isOK = true; is set. But if there is a problem in loading twitter page then it shows following warnings and does not set $isOK = false;
Warning: DOMDocument::load(http://twitter.com/statuses/user_timeline/1234567890.rss) [domdocument.load]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /var/www/vcred/application/controllers/IndexController.php on line 120
I don’t want to see above warning on my webpage in any case. Any idea?
Thanks
Several options:
Suppress all errors for just this function call
which is the same as
Suppressing errors this way is generally frowned upon, as it makes code harder to debug. Like Shrapnel pointed out, you want to disable public display of all error messages on a production system anyway. On Dev systems you are encouraged to use
error_reporting(-1);, which would enableE_ALLandE_STRICT.If you want to use
try/catch, you can also change default error handling and convert all errors to exceptions by doingThis is a global change though and affects everything raised. You’d also have to use
catch(Exception $e)instead ofZend_Exceptionthen in your code, but it would work. Note that the above would convert everything, even Notices, so you will also get an Exception about$isOkbeing undefined if you are trying to access this later. Feel free to adapt the handler to your liking and check out the user comments forset_error_handlerfor more refined versions.Another global change would be to change the application.ini in your application folder, e.g. letting Zend Framework control error handling:
Change these to your needs. They are the same as in PHP.ini, e.g.
display_errors:
display_startup_errors: