In this article you will get to know about the different types of errors in php. But, before letting you know the details and description of different types of errors, we would like to make you aware that what is an error in php?
Well, an error in php may be defined as the improper functioning of a php script or the unexpected termination while executing a php code. An error in php may be caused due to several reasons such as using incorrect syntax, writing incorrect codes, using an outdated php version etc.
Errors are the general things that occur in web development process especially while scripting and executing php codes. Whether being a beginner or a professional, the possibility of an error remains unexpected. However, when it comes to write php codes faster, a professional php programmer may make few mistakes as compared to a beginner.
Now we are going to provide you the description about different types of errors in php in the below section. During the php training students also do lot’s of experiments, but here we will talk about technical php errors.
TYPES OF ERRORS IN PHP
Primarily, errors in php are categorized into four main groups which are discussed as follows.
(1) Syntax Errors
➡ A syntax error occurs when a programmer uses wrong syntax in a php script.
➡ These errors are also known as Parse Errors.
➡ A php script will not be executed when these type of errors occurs.
➡ When separators like semicolon, parentheses, braces, are missed in a php script, then a syntax error occurs.

Example : An example of syntax or parse error is shown below in the image.

Output : You will get the following output/error message of the above php code. Clearly, as we haven’t used the separator ‘semicolon’ in the second echo statement, we are likely to get a parse error message.
(2) Notice Errors
➡ A notice error generally occurs when a programmer attempts to obtain an information of an undefined variable.
➡ These errors are little or limited.
➡ These errors doesn’t affect the execution of a php script.
➡ These errors are not unveiled on the screen to the programmer.

Example : An example of notice error is shown below.

Output : You will get the following output/error message of the above php code. Here, we have defined variable ‘$a’ with value ‘W3training School’. But, we have used variable ‘$b’ to display the output without defining its value. So, we will get a notice error in the output.
(3) Warning Errors
➡ A warning error is generated when a programmer tries to include a file that doesn’t have any existence in the php script.
➡ These errors also occurs when a programmer doesn’t uses correct number of parameters in a function.
➡ Like notice errors, it doesn’t affect the execution of a php script.
➡ These errors are unveiled on the screen to the programmer.

Example : An example of warning error is shown below in the image.

Output : You will get the following output/error message of the above php code. Here, we have included a file named hello.php which is not present in the directory. Therefore, we will get a warning error message in the output.
(4) Fatal Errors
➡ A fatal error occurs when a programmer attempts to call a function which is not previously defined.
➡ These are very critical errors as compared to all the above errors.
➡ A php script will not be executed when these type of errors occurs.
➡ These errors are unveiled on the screen to the programmer.

Example : An example of fatal error is shown below in the image.

Output : You will get the following output/error message of the above php code.Here, we have defined a function fun1() but called an undefined function fun2() as shown in the above example. So a fatal error will be seen as a output on the screen.
ERROR CONSTANTS IN PHP
We have shown below a table of list of error constants with their values used for error reporting.
Error Constant | Value |
E_ERROR | 1 |
E_WARNING | 2 |
E_PARSE | 4 |
E_NOTICE | 8 |
E_CORE_ERROR | 16 |
E_CORE_WARNING | 32 |
E_COMPILE_ERROR | 64 |
E_COMPILE_WARNING | 128 |
E_USER_ERROR | 256 |
E_USER_WARNING | 512 |
E_USER_NOTICE | 1024 |
E_STRICT | 2048 |
E_RECOVERABLE_ERROR | 4096 |
E_DEPRECATED | 8192 |
E_USER_DEPRECATED | 16384 |
E_ALL | 32767 |
Above, we have provided you the best possible information about the different types of errors in php in a very simple and precise manner. Hope, you will get benefited by this post and strengthen your knowledge regarding the concept of errors in php. For further updates, keep log into our php blogs.