...

View Full Version : Unsetting Variables



sir pannels
08-22-2007, 12:40 PM
Hello all,

I have borrowed a function from PHP.net user notes. It cycles through alll the variables in a PHP program and prints them all. See below.



function getDefinedVars($varList, $excludeList)
{
$temp1 = array_values(array_diff(array_keys($varList), $excludeList));
$temp2 = array();
while (list($key, $value) = each($temp1)) {
global $$value;
$temp2[$value] = $$value;
}
return $temp2;
}


The excludeList variable is an array contraining several variables that are not listed such as _ENV and so forth.

I have been attempting to add to this so that it lists the variables and then right after, it unsets all of them. Eqauting in unsetting all the variables in an instance of PHP. I have tried to UNSET the global variable variable during the while loop, however with no success. No errors, however variables remain set.


function getDefinedVars($varList, $excludeList)
{
$temp1 = array_values(array_diff(array_keys($varList), $excludeList));
$temp2 = array();
while (list($key, $value) = each($temp1)) {
global $$value;
$temp2[$value] = $$value;

unset($GLOBALS[$$value]); //added unset here

}
return $temp2;
}


Does anyone have any pointers or ideas here? Your assistance is much appercated.
Warm Regards,
Sir P :D

sir pannels
08-23-2007, 09:30 AM
No idea here?

Cheers very much :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum