what’s
an error?
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.
What are
the different kinds of errors in PHP?
Basically
there are four kinds of errors in PHP, which are as follows:
·
Parse Error (Syntax Error): The parse error occurs if there is a
syntax mistake in the script; the output is Parse error. 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:
1. Unclosed
quotes
2. Missing
or Extra parentheses
3. Unclosed
braces
4. Missing
semicolon
Example:
<?php
echo "Cat";
echo "Dog"
echo "Lion";
?>
echo "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.
·
Fatal Error: 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:
<?php
function fun1()
{
echo "Vineet Saini";
}
fun2();
echo "Fatal Error !!";
?>
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.
·
Warning Error: Warning errors will not stop execution of the script. The main
reason for warning error is to include a missing file or using the incorrect
number of parameters in a function.
Example:
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!!
·
Notice Error: Notice 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:
<?php
$a="Vineet kumar saini";
echo "Notice Error !!";
echo $b;
?>
$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!!
What
are the different types of errors in PHP?
Basically
there are 13 types of errors in PHP, which are as follows:
1. E_ERROR: A fatal
error that causes script termination
2. E_WARNING: Run-time warning that does not cause script termination
3. E_PARSE: Compile time parse error
4. E_NOTICE: Run time notice caused due to error in code
5. E_CORE_ERROR: Fatal errors that occur during PHP’s initial startup
(installation)
6. E_CORE_WARNING: Warnings that occur during PHP’s initial startup
7. E_COMPILE_ERROR: Fatal compile-time errors indication problem with script
8. E_USER_ERROR: User-generated error message
9. E_USER_WARNING: User-generated warning message
10. E_USER_NOTICE:
User-generated notice message
11. E_STRICT: Run-time notices
12. E_RECOVERABLE_ERROR: Catchable fatal error indicating a dangerous error
13. E_ALL: Catches all errors and warnings
No comments:
Post a Comment