bassleader
01-11-2003, 09:44 PM
Hi,
I am trying to use a function to help me debug my scripts, but it seems to have bugs of its own. At the top of my script, after calling session_start() I call the function dump_vars:
function dump_vars()
{
echo "<!-- BEGIN VARIABLE DUMP -->\n\n";
echo "<!-- BEGIN GET VARS -->\n";
echo "<!-- " .dump_array($HTTP_GET_VARS). " -->\n\n";
echo "<!-- BEGIN POST VARS -->\n";
echo "<!-- " .dump_array($HTTP_POST_VARS). " -->\n\n";
echo "<!-- BEGIN SESSION VARS -->\n";
echo "<!-- " .dump_array($HTTP_SESSION_VARS). " -->\n\n";
echo "<!-- BEGIN COOKIE VARS -->\n";
echo "<!-- " .dump_array($HTTP_COOKIE_VARS). " -->\n\n";
echo "<!-- END VARIABLE DUMP -->\n\n\n";
}
The function dump_array($array) looks like this:
function dump_array($array)
{
if (is_array($array))
{
$size = count($array);
$string = "";
if ($size)
{
$count = 0;
//write each element's key and value to to the string
foreach($array as $var => $value)
{
$string .= "$var = $value";
if($count++ < ($size -1))
{
$string .="\n ";
}
}
}
return $string;
}
else
{
return "this is not an array";
}
}
The problem I have is that everything I pass to dump_array returns false for is_array(), therefore all I get is four lines of "this is not an array". Yet I can put a line like:
echo $HTTP_POST_VARS["email"];
into the dump_vars function and get the result I would expect. What am I doing wrong?
BL
I am trying to use a function to help me debug my scripts, but it seems to have bugs of its own. At the top of my script, after calling session_start() I call the function dump_vars:
function dump_vars()
{
echo "<!-- BEGIN VARIABLE DUMP -->\n\n";
echo "<!-- BEGIN GET VARS -->\n";
echo "<!-- " .dump_array($HTTP_GET_VARS). " -->\n\n";
echo "<!-- BEGIN POST VARS -->\n";
echo "<!-- " .dump_array($HTTP_POST_VARS). " -->\n\n";
echo "<!-- BEGIN SESSION VARS -->\n";
echo "<!-- " .dump_array($HTTP_SESSION_VARS). " -->\n\n";
echo "<!-- BEGIN COOKIE VARS -->\n";
echo "<!-- " .dump_array($HTTP_COOKIE_VARS). " -->\n\n";
echo "<!-- END VARIABLE DUMP -->\n\n\n";
}
The function dump_array($array) looks like this:
function dump_array($array)
{
if (is_array($array))
{
$size = count($array);
$string = "";
if ($size)
{
$count = 0;
//write each element's key and value to to the string
foreach($array as $var => $value)
{
$string .= "$var = $value";
if($count++ < ($size -1))
{
$string .="\n ";
}
}
}
return $string;
}
else
{
return "this is not an array";
}
}
The problem I have is that everything I pass to dump_array returns false for is_array(), therefore all I get is four lines of "this is not an array". Yet I can put a line like:
echo $HTTP_POST_VARS["email"];
into the dump_vars function and get the result I would expect. What am I doing wrong?
BL