note 60826 added to function.unset

From: Date: Tue, 17 Jan 2006 23:34:10 +0000
Subject: note 60826 added to function.unset
Groups: php.notes 
Request: Send a blank email to php-notes+get-101993@lists.php.net to get a copy of this message
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 ---- Server IP: 212.124.37.9Probable Submitter: 85.72.174.71 ---- Manual Page -- http://www.php.net/manual/en/function.unset.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60826 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60826&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60826&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60826&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60826&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60826&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60826&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60826&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60826&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#101993) next »