php - Is it possible to Delete a value passed to a method, from within the method -
say have method (which in particular case static method), , method works on given value. once completed there way can automatically in code, delete variable (rather function copy).
i suspect i've read not possible, there no clear declarations of such searching has found.
an example case:
static method:
public static function checkkey($keyvalue = null) { if(!is_null($keyvalue) && !empty($keyvalue)) { if($_session['keyvalue'] == $keyvalue) { unset($keyvalue,$_session['keyvalue']); return true; } unset($keyvalue,$_session['keyvalue']); return false; } return false; } usage:
$valuetobechecked = "i want value unset within function" //php page code abstractclass::checkkey($valuetobechecked); is there way method checkkey above can delete value of $valuetobechecked from within method checkkey?
the fact it's static method shouldn't critical, it's more shape of there way function can delete value set outside funtion/method, when passed variable parameter?
i realise possible if whole thing wrapped in class , variable saved class level variable (unset($this->var)), i'm curious if there's ability "reach" variables outside scope such
public static function checkkey($keyvalue = null) { unset(\$keyvalue); } i have limited experience namespacing that's best guess if possible, how go it.
simplified equiviliant outcome:
what i'm trying reach action, entirely within method:
$valuetobechecked = "something" abstractclass::checkkey($valuetobechecked); unset($valuetobechecked);
you cannot unset variable within function , have effect propagate. per manual:
if variable passed reference unset() inside of function, local variable destroyed. variable in calling environment retain same value before unset() called.
however, can equivalent behavior through pass-by-reference , setting null:
function kill(&$value) { $value = null; } var_dump($x); // null $x = 'foo'; var_dump($x); // 'foo' kill($x); var_dump($x); // null this works because, in php, there's no distinction made between symbol doesn't exist , symbol exists null value.
Comments
Post a Comment