Fuzzy global variables
Posted: Sun Apr 17, 2005 10:37 pm
I'd like to get an array populated with variables that *are* global, but which are not part of:
The idea being that if you set a variable like so:
It would be in the $global_array. Then I can send that out to a var_dump like function, and see what variables are in the global scope, without repetition from the superglobal arrays.
I'm trying to build the script to work with Data Dumpr: http://www.razormotion.com/software/dumpr/
So far, I have a working script for dumping out all the superglobals, other than $GLOBALS.
Every attempt I've made seems to result in either some level of repetition, or in $whatever also being removed. In both cases, that doesnt solve the problem.
---
My current disgusting/incorrect code follows:
Any help is deeply appreciated.
Code: Select all
{$HTTP_POST_VARS, $HTTP_GET_VARS, $HTTP_COOKIE_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES, $_POST, $_GET, $_REQUEST, $_COOKIE, $_FILES, $_ENV, $_SERVER, $_SESSION}Code: Select all
global $whatever;
$whatever = 'testing';I'm trying to build the script to work with Data Dumpr: http://www.razormotion.com/software/dumpr/
So far, I have a working script for dumping out all the superglobals, other than $GLOBALS.
Every attempt I've made seems to result in either some level of repetition, or in $whatever also being removed. In both cases, that doesnt solve the problem.
---
My current disgusting/incorrect code follows:
Code: Select all
<?php
include '[url=http://www.razormotion.com/software/dumpr/]dumpr.php[/url]';
global $test;
$test = 'testing!';
global $whatever;
$whatever = array('something'=>'is something','another'=>'is another');
if (!empty($_ENV))
{
echo "Environment variables<br>";
dumpr($_ENV);
echo "<br>";
}
if (!empty($_SERVER))
{
echo "Server variables<br>";
dumpr($_SERVER);
echo "<br>";
}
if (!empty($_SESSION))
{
echo "Session variables<br>";
dumpr($_SESSION);
echo "<br>";
}
if (!empty($_GET))
{
echo "Get variables<br>";
dumpr($_GET);
echo "<br>";
}
if (!empty($_POST))
{
echo "Post variables<br>";
dumpr($_POST);
echo "<br>";
}
if (!empty($_COOKIE))
{
echo "Cookie variables<br>";
dumpr($_COOKIE);
echo "<br>";
}
if (!empty($_FILES))
{
echo "File variables<br>";
dumpr($_FILES);
echo "<br>";
}
if (!empty($_REQUEST))
{
echo "Request variables<br>";
dumpr($_REQUEST);
echo "<br>";
}
$global_array = $GLOBALS;
$global_array = array_diff($global_array, $_ENV);
//$global_array = array_diff($global_array, $_SERVER);
// Adding this removes the server variables, but also removes the vars we need.
foreach($global_array as $key=>$value)
{
if ($key == 'key' || $key == 'value') // Dont list key itself.
{
unset ($global_array['key']);
unset ($global_array['value']);
}
}
if (!empty($global_array))
{
echo "Global variables<br>";
dumpr($global_array);
echo "<br>";
}
?>