Different types of errors in PHP
Basically there are four types of runtime errors in PHP. The error message is sent to the browser with filename, line number and a message describing the error.
Different type of errors are as following:
- Notice Error
- Warning Error
- Fatal Error
- Parse Error or Syntax Error
1. Notice : These errors are non-critical that PHP encounters while executing a script. In the case of notice error execution of your script does not stop. Mostly the error occurs while accessing a variable that has not yet been defined.
[php]
[/php]
Output
Notice Error!
Notice: Undefined variable: b in /var/www/html/phpcode/error.php on line 4
2. Warnings : These are more serious errors. By default, these errors are displayed to the user, but they do not result in your script termination. Mostly warning errors are due to include a missing file or using the incorrect number of parameters in a function.
[php]
[/php]
Output
Warning Error!
Warning: include(warning.php): failed to open stream: No such file or directory in /var/www/html/phpcode/error.php on line 3Warning: include(): Failed opening ‘warning.php’ for inclusion (include_path=’.:/usr/share/php:/usr/share/pear:’) in /var/www/html/phpcode/error.php on line 3
3. Fatal : These are critical errors. These errors cause the immediate termination of your script. if you are trying to instantiating an object of a non-existent class, or calling a non-existent function, then the output is a fatal error that stops the execution of your script.
[php]
[/php]
Output
Execution starts here!
Fatal error: Call to undefined function fun2() in /var/www/html/phpcode/error.php on line 7
4. Parse : These are critical errors occurs if there is a syntax mistake in the script. Parse error also stops the execution of your script. The common reasons for parse errors are Unclosed quotes, Missing or extra parentheses, Unclosed braces, Missing semicolon, etc.
Output
PHP Parse error: syntax error, unexpected ‘if’ (T_IF), expecting ‘,’ or ‘;’ in /var/www/html/phpcode/error.php on line 4