PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




Error Handling in PHP


Tutorials »Php »

Topic

How to stop or block error, supress warning messages in the page?



Explanation

Error handling in php can be done very easily

Stop error reporting completely in PHP:
    To completely turn off error or warning messages on web pages you can use the function "error_reporting(0);"

For example, here we try to open a file that does not exit, we will get a warning as below
Code Used: e.g:
<?php
fopen('test.txt',r);
echo("test for error message");
?>

Result:
Warning: fopen(test.txt) [function.fopen]: failed to open stream: No such file or directory in /home/myscript/public_html/tutorials/php/error-handling/warningMessages.php on line 72
test for error message

Now with the same code we "set error reporting as 0" before calling other methods.
Code Used: e.g:
<?php
error_reporting(0);
fopen('test.txt',r);
echo("test for turning off warning message");
?>

Result: test for turning off warning message

So we have supressed or blocked all warning and error that are shown on web pages.

We can also use ini_set to turn off any error message being displayed. The property to be used is "display_errors". Note that using ini_set will overwrite all other related properties set using functions.
Code Used: e.g:
<?php
ini_set("display_errors",0);
.........
.........
.........
?>
To reset, use value as 1 instead of 0.

Next>> learn to block warnings on specific operations.





Other Links

web hosting