How many errors are there in php?

Introduction

An error is a type of mistake. We can say an error is a condition of having incorrect or false knowledge or an error is defined as an unexpected, invalid program state from which it is impossible to recover.

Error can also be defined as "a deviation from accuracy or correctness". A "mistake" is an error caused by a fault: the fault being misjudgment, carelessness, or forgetfulness. An error message with filename, line number and a message describing the error is sent to the browser.

Types of error

Basically there are four types of errors in PHP, which are as follows:

  • Parse Error (Syntax Error)
  • Fatal Error
  • Warning Error
  • Notice Error

1. Parse Errors (syntax errors)

The parse error occurs if there is a syntax mistake in the script; the output is Parse errors. A parse error stops the execution of the script. There are many reasons for the occurrence of parse errors in PHP. The common reasons for parse errors are as follows:

Common reason of syntax errors are:

  • Unclosed quotes
  • Missing or Extra parentheses
  • Unclosed braces
  • Missing semicolon

Exampleecho "Cat";
echo "Dog"
echo "Lion";
?>

Output

In the above code we missed the semicolon in the second line. When that happens there will be a parse or syntax error which stops execution of the script, as in the following image:

How many errors are there in php?

2. Fatal Errors

Fatal errors are caused when PHP understands what you've written, however what you're asking it to do can't be done. Fatal errors stop the execution of the script. If you are trying to access the undefined functions, then the output is a fatal error.

Example

function fun1()
{
echo "Vineet Saini";
}
fun2();
echo "Fatal Error !!";
?>

Output

In the above code we defined a function fun1 but we call another function fun2 i.e. func2 is not defined. So a fatal error will be produced that stops the execution of the script. Like as in the following image.

How many errors are there in php?

3. Warning Errors

Warning errors will not stop execution of the script. The main reason for warning errors are to include a missing file or using the incorrect number of parameters in a function.

Example
echo "Warning Error!!";
include ("Welcome.php");
?>

Output

In the above code we include a welcome.php file, however the welcome.php file does not exist in the directory. So there will be a warning error produced but that does not stop the execution of the script i.e. you will see a message Warning Error !!. Like in the following image:

How many errors are there in php?

4. Notice Errors

Notice that an error is the same as a warning error i.e. in the notice error execution of the script does not stop. Notice that the error occurs when you try to access the undefined variable, then produce a notice error.

Example

$a="Vineet kumar saini";
echo "Notice Error !!";
echo $b;
?>

Output

In the above code we defined a variable which named $a. But we call another variable i.e. $b, which is not defined. So there will be a notice error produced but execution of the script does not stop, you will see a message Notice Error !!. Like in the following image:

How many errors are there in php?

Conclusion

So in this article you saw types of errors in PHP. Using this article one can easily understand the concept of errors in PHP.

Some Helpful Resources

  • Arrays in PHP
  • Simple HTML embedded application in PHP
  • File uploading in PHP using XAMPP
  • Exception handling in PHP: Part 1
  • Exception handling in PHP: Part 2

What is error and types of error in PHP?

An error message is displayed on your browser containing the filename along with location, a message describing the error, and the line number in which error has occurred. There are usually different types of error. In PHP, mainly four types of errors are considered: Syntax Error or Parse Error. Fatal Error.

How show all errors in PHP?

Quickly Show All PHP Errors The quickest way to display all php errors and warnings is to add these lines to your PHP code file: ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);

What is PHP fatal error?

Fatal errors crash the program. There are three types of fatal errors in PHP: Startup fatal error: This error occurs when a system can't run the code during installation. Compile time fatal error: This error occurs if a call is made to a non-existent code or variable.

What is PHP report error?

The error_reporting() function specifies which errors are reported. PHP has many levels of errors, and using this function sets that level for the current script.