#19146 [NEW]: Old Value kept after unset() on a &$parameter inside function.

From: Date: Wed, 28 Aug 2002 13:17:09 +0000
Subject: #19146 [NEW]: Old Value kept after unset() on a &$parameter inside function.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-18028@lists.php.net to get a copy of this message
From: purodha.blissenbach@hostsharing.net Operating system: Linux, diverse Debian PHP version: 4.1.2 PHP Bug Type: Scripting Engine problem Bug description: Old Value kept after unset() on a &$parameter inside function. unset()ting a variable passed by reference does not destroy this variable, but rather protects it's value against being further altered inside the function. < ? php function subroutine(&$byname, $assign, $unset) { if($assign) $byname = 'set by subroutine'; if($unset) unset($byname); $byname = 'finally set inside subroutine'; } $byname = 'Set Outside!'; subroutine($byname, TRUE, FALSE); echo ('<p> 1st. call: ($assign=TRUE, $unset=FALSE) returns $byname="'.$byname.'"</p>'); $byname = 'Set Outside!'; subroutine($byname, FALSE, FALSE); echo ('<p> 2nd. call: ($assign=FALSE, $unset=FALSE) returns $byname="'.$byname.'"</p>'); $byname = 'Set Outside!'; subroutine($byname, TRUE, TRUE); echo ('<p> 3rd. call: ($assign=TRUE, $unset=TRUE) returns $byname="<b>'.$byname.'</b>"</p>'); $byname = 'Set Outside!'; subroutine($byname, FALSE, TRUE); echo ('<p> 4th. call: ($assign=FALSE, $unset=TRUE) returns $byname="<b>'.$byname.'"</p></b>'); ? > Outputs: 1st. call: ($assign=TRUE, $unset=FALSE) returns $byname="finally set inside subroutine" 2nd. call: ($assign=FALSE, $unset=FALSE) returns $byname="finally set inside subroutine" 3rd. call: ($assign=TRUE, $unset=TRUE) returns $byname="set by subroutine" 4th. call: ($assign=FALSE, $unset=TRUE) returns $byname="Set Outside!" More information and a live Demo can be obtained from http://purodha.hostsharing.de/hostsharing/menu0/test_by_name.php -- Edit bug report at http://bugs.php.net/?id=19146&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=19146&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=19146&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=19146&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=19146&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=19146&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=19146&r=support Expected behavior: http://bugs.php.net/fix.php?id=19146&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=19146&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=19146&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=19146&r=globals

« previous php.bugs (#18028) next »