TYPE OF ERRORS IN PHP
There are basically four type of errors in php .
- Fatal error
- Parse error
It is simple message to end-user .
it does not stop execution of script.
If we are trying to access undefined variable , output is notice message.
<?php Error_reporting(E_all) // reports all errors. Echo $k; Echo “hello”; ?>
Output: notice error
By default , we con not see notice message on browser to display notice message, we should use error_reporting(E_ALL)function.
It is same as notice, does not stop execution of script. If we are trying to access undefined constants, output is warning message.
Constant is same as variable, but constant value con not be changed.
In php, using function, we can declare constants.
Using constant function , we can access constants.
<?php Define(“city”, “AAA”); Echo constant(“city”); Echo constant(“stt”); // warning Echo ”hello”; ?>
Fatal error stops the execution of script from the line when error is occurred .
If we try to access undefined functions. Output is fatal error.
<?php Echo “codelack” Defin(“city”,”AAA”); // fatal error Echo “hello”; ?>
Parse Error :-
If there is syntax mistake in the script, output is parse error.
Parse error stops execution of complete.
<?php Echo ”first line “; Echo “2nd line” //syntax error Echo “3rd line” ; ?>
Output : parse error (stops full script)
<?php Echo” first line “; Echo “2nd line”; Echo “3rd line “ // executes since last line its no need of ; ?>
Output : first line 2nd line 3rd line
Using this function, we check whether the function is set with any value or not
<?php $x=100; Echo isset($x); ?>
Using this function, we can delete the value of variable .
<?php $x=100; Unset($x); Echo isset($x); ?>
Output : false (nothing displays)