H I O X INDIA
FREE PHP Topics
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Templates 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)
Español Français 中文 Deutsch Portuguese Japanese தமிழ்
 Forums   Hosting   Internet Stats   Easy Calculation   FUN Games 

PHP Topics
Introduction
Syntax
Data Types
Variables
Operators
Control Structures
Functions
Pre-defined Function
Calendar Functions
Date and Time
Array Functions
Array Functions List1
Array Functions List2
Math Functions
PHP Mysql Functions
File Handling
Error Handling
DB Size
PHP Mail
String Tokens
String Functions
String Functions List1
String Functions List2
Session Functions
Cookies Functions
Form Variables
Running PHP from JS
Array To JS
Array to PHP
Encryption
Common Header
Ask Your Doubts
More about PHP
Feedback





Error Handling in 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.





privacypolicy     licence     sitemap
(c) copyright, 2004 hioxindia.com