good evening,
i have these five functions that i use to reduce server load :
// unset all vars
function unset_all_vars()
{
$vars = func_get_args();
foreach($vars[0] as $key => $val)
{
unset($GLOBALS[$key]);
}
return serialize($vars[0]);
}
unset_all_vars(get_defined_vars());
// unset all const
function unset_all_const()
{
$vars = func_get_args();
foreach($vars[0] as $key => $val)
{
unset($key);
}
return serialize($vars[0]);
}
unset_all_const(get_defined_constants());
// unset all functions
function unset_all_functions()
{
$vars = func_get_args();
foreach($vars[0] as $key => $val)
{
unset($key);
}
return serialize($vars[0]);
}
unset_all_functions(get_defined_functions());
// unset all classes
function unset_all_classes()
{
$vars = func_get_args();
foreach($vars[0] as $x => $v)
{
unset($x);
}
return serialize($vars[0]);
}
unset_all_classes(get_declared_classes());
// unset all interfaces
function unset_all_interfaces()
{
$vars = func_get_args();
foreach($vars[0] as $x => $v)
{
unset($x);
}
return serialize($vars[0]);
}
unset_all_interfaces(get_declared_interfaces());
?>
function 1 unset all vars
function 2 unset all const
function 3 unset all functions
function 4 unset all classes
function 5 unset all interfaces
are they good ?
is there some other functions better than them ? or additional to them ?
Why use functions like this at all? Even if they would work, a PHP script runs only for a second at most, after which it will clear up everything it has allocated. Freeing things inbetween is particularly useful for scripts that run for a long time and allocate lots of resources that are soon not needed anymore, but this is quite uncommon for web pages, for which PHP is mainly used.
The naming is wrong too, since they don’t deallocate ‘all’ items, but only the ones they are passed.