note 60826 rejected from function.unset by betz

From: Date: Tue, 21 Mar 2006 15:01:56 +0000
Subject: note 60826 rejected from function.unset by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-106155@lists.php.net to get a copy of this message
Note Submitter: Daniel ---- If you have a function which uses variables like arrays passed by reference and you want to unset/destroy this var/array in that function so that also the original is unseted/destroyed you can't use unset(). It will only destry that var in the function, not the original. You have to set the Var/Array to null. Take this example: <?php class testUnset{ function one() { $testvar = "something"; $this->two($testvar); echo $testvar; } function two( &$var ) { $var = $var . ' more'; unset($var); // won't work $var = null; //will work } } $obj =& new testUnset(); $obj->one(); ?> if you use unset($var) nothing will happen. function one will echos: "something more" if you use $var = null there won't be any output Maybe it's a bug. Maybe not. Tested with php5 and 4

« previous php.notes (#106155) next »