error in php

TYPE OF ERRORS IN PHP

There are basically  four type of errors in php .

  1. Notice
  2. Warning
  3. Fatal error
  4. Parse error

 

Notice

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.

Example:

 

 <?php

 Error_reporting(E_all)  // reports all errors.

Echo $k;

Echo “hello”;

?>

 

Output:   notice error

Hello

By default , we con not see notice message on  browser to display notice message, we should use error_reporting(E_ALL)function.

 

Warning:-

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.

 

Example:-

<?php

Define(“city”, “AAA”);

Echo constant(“city”);

Echo constant(“stt”); // warning

Echo ”hello”;

?>

 

Output :

AAA

Warning

Hello

 

Fatal error

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.

Example :-

<?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.

Example :-

<?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 

Isset() :-

Using this function, we check whether the function is set with any value or not

Example:-

<?php

$x=100;

Echo isset($x);

?>

Output: 1(true)

Unset() :-

Using  this    function, we can delete the value of variable  .

<?php

$x=100;

Unset($x);

Echo isset($x);

?>

Output :   false (nothing displays)

Scroll Up