Debugging Functions in Php : 

1. die()  function : -


<?php

die("--script Terminated---");

echo $x;

 

2. exit()  function : -

<?php


#exit is langauge Construct so you can use without parenthesis

exit;


#exit with Argument

exit("Line Terminated");


#Index Wise Exit

exit(0); #Script Terminate

exit(1);

exit(2);

exit(3);

exit(4);

echo $x;


3. pr()  function : -



<?php

function pr($arg){

echo "<pre>";

if(is_array($arg)){

print_r($arg);

}elseif(is_null($arg) or is_bool($arg) or is_object($arg)){

var_dump($arg);

}else{

echo $arg;

}

echo "</pre>";


}


pr(10);

pr("Hello");

pr([10,20,30]);

pr(true);



4. prx()  function : -



<?php

function prx($arg=""){

echo "<pre>";

if(is_array($arg)){

print_r($arg);

}elseif(is_null($arg) or is_bool($arg) or is_object($arg)){

var_dump($arg);

}else{

echo $arg;

}

echo "</pre>";

exit;

}


prx(10);




5. print_r()  function : -



<?php

#print_r for debugging Means Printing in a Formatted Way


$arr = array(10,20,30);

echo "<pre style='background-color:black;color:white;font-family:rockwell;'>";

print_r($arr);

echo "<pre/>";





6. var_dump()  function : -



<?php


#vardump: Used to Perform Postmortum of a Varaible : Datatype and Its value with no of

#character in its data value but thing is it should be string Type


$arr = array(10,"20",true,[10,20,30],10.5);


echo "<pre>";

var_dump($arr);

echo "</pre>";

#exit;


#var_dump can be used to print :Boolean false which echo, print,print_r no one can print

$x=false;

echo $x;


print($x);

print_r($x);

var_dump($x);//this is Powerful


echo "<hr/>";

#var_dump supports multi Arguments

var_dump(10,20,30);


echo "<hr/>";

#var_dump is not a langauge Construct : parenthesis are mendatory

var_dump(20);


echo "<hr/>";

#var_dump: can be used to print Objects

class Test{

public $a=10;

public $b=20;

public $c="apple";

}


$obj = new Test();

var_dump($obj);



6. var_export()  function : -


<?php

#difference B/w var_dump and var_export
#var_export is same as var_dump but it print outs the output in a Structure Manner
# or valid php code

$arr = array(10,"20",true,[10,20,30],10.5);
var_export($arr);
echo "<hr/>";
class Test{
public $a=10;
public $b=20;
public $c="apple";
}
$obj = new Test();
var_export($obj);


Debugging Functions in PHP