There
are basically 4 types of errors in PHP. They are –
1. Notice – It is a
simple message to end-user. It does not stop execution of script. If we are
trying to access undefined variable, output is notice message.
Example –
<?php
echo $y;
echo "hi";
?>
Output –
Notice: Undefined variable: y in
C:\Users\om\workspace\PhpProjec\first.php on line 2
hi
2. Warning – It is
same as notice, doesn’t stop execution of script. If we are trying to access
undefined constants, output is warning message. Constant is same as variable, but
constant value cannot be changed. In PHP, using define function we declare constants. Using constant function we
can access constants.
Example –
<?php
define("city","guwahati");
echo constant("city");
echo constant("state");
echo "hi";
?>
Output –
guwahati
Warning: constant(): Couldn't find constant state in
C:\Users\om\workspace\PhpProjec\first.php on line 4
Hi
3. Fatal error – Fatal error stops the execution of script from the line where
error is occurred. If we try to access undefined function, output is fatal
error.
Example –
<?php
echo "Rakesh";
defin("city","guwahati");
echo "hi";
?>
Output –
Rakesh
Fatal error: Call to undefined
function defin() in C:\Users\om\workspace\PhpProjec\first.php on line 3
4. Parse error – If there is any syntax mistake in the script, output is parse
error. Parse error stops execution of complete script.
Example –
<?php
echo "Rakesh";
echo "Bikash"
echo
"Apurba";
?>
Output –
Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting
',' or ';' in C:\Users\om\workspace\PhpProjec\first.php on line 4
Example –
<?php
echo "Rakesh
";
echo "Bikash
";
echo "Apurba"
// executes since last line does not require ;
?>
Output –
Rakesh Bikash Apurba
No comments:
Post a Comment