In this tutorial, we are going to see types of errors in PHP. When we write program we get different types of error while execution.
But if we know the meaning of errors or types of errors then we can easily handle it by solving.
This tutorial will help you to understand different types of errors and its cause of occurence.
What is an Error ?
An error is a mistake or fault in a program caused by writing incorrect code, syntax or wrong logic.
An error message is display in browser containing file with location, an error message and line number in which error has occured.
In PHP there are 4 types of errors.
- Parse error or Syntax Error:
- Fatal Error:
- Warning Errors:
- Notice Error:
Let’s understand each in details
Syntax Error or Parse Error
A syntax error is a mistake done by the programmer in the source code of the program.
It is also known as parse error. Compiler catch this type of error at compile time.
These errors occurs due to common mistake done in code like missing semicolon, missing parenthesis, unclosed brackets and unclose quotes, etc.
Example:
<?php
echo "Phpcluster";
echo "Vikash Kumar Singh"
echo "Programming Blog";
?>
Fatal Error
This is another type of error in PHP. Fatal errors occured when compiler compile the code but do not understand undeclared function.
It means this error comes when we use function without defining it.
Example:
<?php
function add($x, $y) {
$sum = $x + $y;
echo $sum;
}
$x = 10;
$y = 6;
add($x, $y);
diff($x, $y);
?>
Warning Errors
This is also a type of error which occurs due to including a missing file.
When PHP function call the missing file which does not exists then it generates warning errors.
Example:
<?php
$x = "Phpcluster Programming Blog";
include ("abc.php"); ?>
Notice Error
Notice error is similar to Warning error. When program contains something wrong then the notice error occurs but it allows the execution of the script.
Example:
<?php
$y = "Phpcluster blog";
echo $y;
echo $x;
?>