- In a programmer, error is a mistake that may be caused by writing incorrect code or incorrect syntax.
- An error message is displayed on your browser containing the filename along with a message describing the error, location and the line number in which error has occurred.
- In PHP there are various types of errors that contains basically four main types of errors, they are
- Syntax Error or Parse Error
- Fatal Error
- Warning Error
- Notice Error
Syntax Error or Parse Error
- A syntax error is a mistake in the syntax of source code, which can be done by programmers due to their lack of knowledge or concern.
- At compile time compiler is used to catch the syntax error.
- Due to common reasons these errors can occur like missing semicolon, unclosed quotes, or unclosed brackets, extra or missing parentheses and many more.
- While compiling the program syntax error can be caught by the compiler and gives a syntax error or parse error message.
Sample Code
Output
Fatal Error
- Fatal error is another type of error, which is occurred due to the use of undefined function.
- The PHP compiler understands the PHP code and also recognizes the undefined function.
- PHP compiler generates a fatal error, when a function is called without providing its definition.
Sample Code
Output
Warning Error
- When the programmer tries to include a missing file there warning error is generated.
- The PHP function calls that missing file which does not exist and warning error does not stop/prevent the execution of the program.
Sample Code
Output
Notice Error
- Notice error is also same as warning error, when program contains something wrong, the notice error occurs.
- Including a notice error, it allows/continue the execution of the program.
- Notice error does not prevent the execution of the code and generally it occurs when we try to use or access a variable which is undefined.
Sample Code
Output