Errors in PHP:

An error is a type of mistake. We can also say that an error is deviation from actual result.

In PHP if there is an error in scripting than it will throw the error as per it severity. Also the error message will display on the browser with the error type, file name, line number and a small message that describes the error.

 Types of PHP Errors:

In PHP there are four common errors that occur when there is some mistake in Scripting.

  • Parse Error
  • Fatal Error
  • Warning Error
  • Notice Error

 Parse Error:

In PHP Parse Error is occurs when there is a syntax error in the script. If there is a syntax error in script than the Parse error occurs and it will stop the execution of the code. There are so many reasons of Parse error but some common reasons are as follows:

  • Missing semicolon
  • Quotes are not closed
  • Extra or missing parentheses
  • Braces are not closed or unclosed braces

 Example:

In following example we are not terminating the statement with semicolon so it will throw a Parse Error

 Result:

 Fatal Error in PHP:

In PHP Fatal Errors are known as Critical Errors. Fatal error will stop the execution of the script means it will terminate the execution of script immediate like Parse error. For example you are accessing an undefined function so it will throw Fatal Error.

 Example:

In following example we are using a function which is not defined in script and we are calling that function.

 Result:

 Warning Error in PHP:

In PHP Warning Errors are occurred when you are including a file which does not exist and warning errors will not stop the execution of scripting. It just throws the error and the script will execute.

Example:

In following example we are include a file which is not exits and the other statements of script will executed and a warning message display on browser for the file.

 Result:

 Notice Error in PHP:

In PHP Notice Errors are non-critical that means it will not affect the execution of the code as like Warnings. Notice errors are occurs when you trying to use a variable which is not defined in script.

Example:

In following example we are using an undefined variable so it will throw the Notice on browser

 Result:

 Difference between Fatal Error and Warning and Notice:

The main difference between fatal error and warning and notice is Fatal Errors are very critical error and have to resolve because it stops the execution of script whereas warning and notice are not that much critical and will not stop the execution of Script.

 

Leave a Reply

Your email address will not be published. Required fields are marked *