note 90187 added to debugger
| From: | tomboul at osu1 dot php dot net | Date: | Thu, 09 Apr 2009 10:51:58 +0000 |
| Subject: | note 90187 added to debugger | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152997@lists.php.net to get a copy of this message | ||
Here a best printed var_dump : show_php
It's a reccursive function for output many kind of structured data (array, class, etc ...)
<?php
function show_php($var,$indent=' ',$niv='0')
{
$str='';
if(is_array($var)) {
$str.= "<b>[array][".count($var)."]</b><br />";
foreach($var as $k=>$v) {
for($i=0;$i<$niv;$i++) $str.= $indent;
$str.= "$indent<em>\"{$k}\"=></em>";
$str.=show_php($v,$indent,$niv+1);
}
}
else if(is_object($var)) {
$str.= "<b>[objet]-class=[".get_class($var)."]-method=[";
$arr = get_class_methods($var);
foreach ($arr as $method) {
$str .= "[function $method()]";
}
$str.="]-";
$str.="</b>";
$str.=show_php(get_object_vars($var),$indent,$niv+1);
}
else {
$str.= "<em>[".gettype($var)."]</em>=[{$var}]<br />";
}
return($str);
}
?>
EXAMPLE :
array example to debug :
<?php
$tab=array(
"first"=>"firstValue",
"second"=>array(
"first"=>1,
"second"=>2,
"third"=>array(
"first"=>"one",
"second"=>"two"
),
),
);
?>
result of show_php :
<?php
echo "tab=".show_php($tab);
?>
tab=[array][2]
"first"=>[string]=[firstValue]
"second"=>[array][3]
"first"=>[integer]=[1]
"second"=>[integer]=[2]
"third"=>[array][2]
"first"=>[string]=[one]
"second"=>[string]=[two]
result of var_dump :
<?php
echo "tab=";
var_dump($tab);
echo "<br>";
?>
tab=array(2) { ["first"]=> string(10) "firstValue" ["second"]=>
array(3) { ["first"]=> int(1) ["second"]=> int(2) ["third"]=>
array(2) { ["first"]=> string(3) "one" ["second"]=> string(3)
"two" } } }
----
Server IP: 195.221.21.36
Probable Submitter: 77.204.242.237
----
Manual Page -- http://www.php.net/manual/en/debugger.php
Edit -- https://master.php.net/note/edit/90187
Del: integrated -- https://master.php.net/note/delete/90187/integrated
Del: useless -- https://master.php.net/note/delete/90187/useless
Del: bad code -- https://master.php.net/note/delete/90187/bad+code
Del: spam -- https://master.php.net/note/delete/90187/spam
Del: non-english -- https://master.php.net/note/delete/90187/non-english
Del: in docs -- https://master.php.net/note/delete/90187/in+docs
Del: other reasons-- https://master.php.net/note/delete/90187
Reject -- https://master.php.net/note/reject/90187
Search -- https://master.php.net/manage/user-notes.php