Which One is Better?
See two debugging functions:
———————1st One—————————
function dBug($dump)
{
print "<pre>";
var_dump($dump);
print "</pre>";
}
———————————————————-
This one gives debug-data along with datatypes and lengths.
—————————2nd One———————–
function dBug($dump)
{
print "<pre>";
print_r($dump);
print "</pre>";
}
———————————————————–
This one gives debug-data in a formatted way.
Here’s an example:
$myname = array(
'last_name' =>'Razzaque',
'first_name' =>'MA',
'nick_name' =>'Rupom'
);
Result of the first dBug():
array(3) {
["last_name"]=>
string(8) "Razzaque"
["first_name"]=>
string(2) "MA"
["nick_name"]=>
string(5) "Rupom"
}
Result of the second dBug():
Array
(
[last_name] => Razzaque
[first_name] => MA
[nick_name] => Rupom
)
The second dBug() gives more readable debug-data than that of the first one. But the first dBug() is more informative than the second one. So friends, which one should we choose?
Usually I use second one for a more readable debug-data.
[Rupom]
March 12th, 2006 at 5:12 pm
Generally I am used to with second one for debugging purpose. I think first one will be helpful for debugging with large and complex data.
March 12th, 2006 at 5:15 pm
Thanks for your comment.
March 12th, 2006 at 8:40 pm
It depends on different requirement …
When i want to chkout only the value and property i use print_r
for more info like length of array and type i will use var_dump…
Though this are too handy try to use log4php… and use file appender so your debug output will be available in local file which u can chkout offline…
Thank u wish you best…
March 13th, 2006 at 9:24 am
Thanks Hasan. The actual thing is requirement. Which one will be used depends on requirements. You are right.
Wish you all the best….
July 10th, 2006 at 4:34 pm
[code]
function dBug($dump)
{
print “”;
print_r(var_dump($dump));
print “”;
}
[/code]