I am trying to make a function that combines the assignment of variables with their subsequent destruction. I had in mind to do something like this:
function setunset(&$sesion){
$salida = $sesion;
unset($sesion);
return $salida;
}
$_SESSION['uno'] = '1';
$uno = setunset($_SESSION['uno']);
echo $uno; // Devuelve 1
echo $_SESSION['uno'] // Devuelve "undefined index"
I am seeing that this as it would not be possible because the destruction of the variable remains within the scope of the function and therefore, $_SESSION['uno']
would still exist. ( PHP Documentation )
Is there any other way to do it? Or will I have to settle for making it classic (first assign and then destroy)?