Important alert: (current site time 7/15/2013 10:18:38 AM EDT)
 

VB icon

DebugVariables

Email
Submitted on: 10/29/2000 1:40:52 PM
By: PHP Code Exchange  
Level: Intermediate
User Rating: By 1 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 9436
 
     One function to show any php-variable, even arrays and objects in an understandable way. by Thomas Hansmann
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: DebugVariables
// Description:One function to show any php-variable, even arrays and objects in an understandable way. by Thomas Hansmann
// By: PHP Code Exchange
//**************************************

<?php
 # coded by thomas hansmann (thomas@thoftware.de) and if you copy it,
 # you're right ;-)
 # if you find this code usefull, please send me an email. thanks...
 # only use the first 2 arguments (a describing name and the variable
 # itself, $a and $o are used only from within the function).
 function show_var($n,$v,$a=0,$o=0) {
$m1 = "is an array";
$m2 = "is an object";
$m3 = "functions";
$t = "<table class=debug border=0 cellpadding=0 cellspacing=0>";
if (!$a) echo $t;
echo "<tr><td class=debug valign=top>";
echo ($n == "[\"~\"]")?"<br>$m3: ":"$n ";
echo "</td><td class=debug>";
if (is_array($v)) {
 echo ($o?"":"$m1:<br>")."$t";
 for (reset($v);list($k,$vv) = each($v);show_var("[\"$k\"]",$vv,$a+1));
 echo "</table>";
} elseif (is_object($v)) { # very tricky
 echo "$m2:<br>";
 $v = serialize($v); # object -> string
 $v = "a".substr($v,1);# fake an array
 $f = unserialize($v);# string -> array
 $v = ereg_replace("s:[^;]+;i:0;","",$v); # delete functions
 $v = unserialize($v);# string -> array
 for (reset($v);list($key,$val) = each($v);unset($f[$key]));
 for (reset($f);list($key,$val) = each($f);$v["~"].="$key(); ");
 show_var("",$v,$a+1,1);
} elseif ($n == "[\"~\"]") {
 echo "<br>$v<br>";
} elseif (is_string($v)) {
 echo ": \"$v\"<br>";
} else echo " : $v<br>";
echo "</td></tr>";
if (!$a) echo "</table>";
 }
?>


Other 192 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.