Skip or Hide PHP errors / warnings

497px-Error.svg

Errors are hints from compiler for the programmer to correct. But sometimes we face some unwanted or dynamic error. For example,

$content = file_get_contents(http://www.twitter.com/feed/234);

Here , the url is invalid, or the server of the url is down , PHP shows Warning: Failed to open stream or file access is disabled.

Use @ in front of such function never shows any warning message.

Eg: $content = @file_get_contents(url here) or die (‘Sorry , cannot access the url’);

Another method is runtime PHP ini editing

ini_set (‘display_errors’, 0);

//write the code which may cause error here

ini_set (‘display_errors’, 1);

But , these things are not recommended. Only for unavoidable situations.

1 Comments

One Response to “Skip or Hide PHP errors / warnings”

  1. Sajith M.R April 30, 2010 at 5:31 am #

    You can also do this with error_reporting on or off, dynamically

Leave a Reply

More in php (27 of 101 articles)


Some days back I got a new website from my friend Lee to generate favicon for website. Here is the ...