Saturday 6 July 2013

Types Of Errors In Php

Types of Errors in php


There are four types of errors

1.Notice
2.Warning
3.Fatal Error
4.Parse Error


1.Notice


It is nothing but a samll information to user. If we are trying to access undefined variable. The Output is Notice.Notice does'nt stop the execution.

Example:
<?php
$var1="car";
$var 2=3;
echo $var1'.'$var2;
echo $var3;// Notice error
  ?>

By default we cannot see the notice message on browser.Because , The configuration setting ie error_reporting value is "E_ALL" & ~E_NOICE , The notice are displayed by the Browser. we can also display notice within the program by using Error_Reporting(E_ALL).

Example:

<?php
error_reporting(E_ALL)
$var1="car";
$var 2=3;
echo $var1'.'$var2;
echo $var3;// Notice error
?>

2.Warning:


If is same as notice does not stop script execution.It occurs if we are tying to call undefine constant.
In php,we can declare constant by using define.

Example:

<?php
define("sno",10)
echo constant("sno");
echo constant("a");// undefined constant
?>

3.Fatal error:

It stop the execution of webpage from line where the error occurred. If we try to call undefined function.

Example:
<?php
 function f1()
{
echo "welcome  to www.online24by7.info";
}
f1():
f2();// undefined function
?>

4.Parse Error:

It stop the Exection of complete script if there is syntax error

Example

<?php
echo "line 1"
echo "hi"// does not contain semicolon 
?>

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More