Total 4 Different Types Of Errors In PHP  


1.) Warning Error

2.) Notice Error

3.) Parse Error

4.) Fatal Error 


1. Warning Error


The most common causes of warning errors are Calling on an external file that does not exist in the directory.A 

Warning error in PHP does not stop the script from running.


<?php

echo "Warning error in PHP ";

//there are include file in webpage the external file that does not exist in the directory

include ("config/external_file.php");

?>


Output : 

PHP Warning:  include("config/external_file.php"): failed to 

open stream: No such file or directory in 

/home/config/external_file.php on line 15


PHP Warning:  include(): Failed opening 'config/external_file.php'

 for inclusion (include_path='.:/usr/share/php') in 

/home/config/external_file.php on line 15


2.) Notice Error


Notice errors when occur if the script needs access to an undefined variable. Notice errors are minor errors. They are similar to warning errors, as they also don’t stop code execution. 


<?php

$a="Defined error";

echo "Notice error in PHP ";

// calling of undefined Variable $b

echo $b;

?>


Output : 

PHP Notice:  Undefined variable: CodeHubDeep in 

/home/index.php on line 15

Notice error in PHP


3.) Parse Error (Syntax Error)

Parse errors are caused by misused or missing symbols in a syntax. The compiler catches the error and terminates the script.


Parse errors are caused by-


1.) Unclosed brackets or quotes or parentheses

2.) Missing or extra semicolons

3.) Misspellings


<?php

echo "Deepak";

echo "CodeHubDeep";

echo "CodeHubDeep.blogspot.com"

?>


4.) Fatal Error

Fatal errors are ones that craswhen occur then An undefined function or class in the script is the main reason for this type of error.

<?php

function sub()

{

$sub=6-1;

echo "The sub= ".$sub;

}

Desc();//Calling Undefined Function Desc();

?>


PHP Fatal error:  Uncaught Error: Call to undefined function Desc() in /home/index.php:15


There are three (3) types of fatal errors:

Startup fatal error (when the system can’t run the code at installation)

Compile time fatal error (when a programmer tries to use nonexistent data)

Runtime fatal error (happens while the program is running, causing the code to stop working completely)

For instance, the following script would result in a fatal error:


PHP All Type Error