X

Rate Us :



Share with Friends :

Menu

Types of errors in PHP :

There are four types of errors in PHP :

  • Notice




  • Warning




  • Fatal error




  • Parse error




Notice :

It is nothing but small information to the user. If we are trying to access undefined variables then this error occurs. Notice doesn't stop script execution. By default we cannot see the notice message on Browser because the configuration setting i.e. error-reporting value is "E_ALL" & ~E_NOTICE, which means to display all error messages except NOTICE. BY removing ~E_NOTICE, the notice is displayed by the Browser.

Example :

<?php $a = 100; echo $x; echo $y; ?>

Output :

Notice

We can also display notice within the program by using Error_Reporting(E_ALL);

Example :

<?php Error_Reporting(E_ALL); $x = 100; echo $y; ?>

Output :

Notice

Warning :

It is same as Notice as it doesn't stop script execution. It occurs if we are trying to call undefined constants. In PHP, we can declare constants by using define.

Example :

<?php define("n" , 10); echo constant("s"); ?>

Output :

Warning

Fatal error :

It stops the execution of web page, from the line where error occurred. If we try to call undefined function then fatal error occurs.

Example :

<?php function fn() { echo "HELLO"; } Sn(); ?>

Output :

Fatal error

Parse error :

It stops the execution of complete script if there is syntax mismatch.

Example :

<?php echo "HELLO"; echo "123" echo "ABC"; ?>

Output :

Parse error