#19146 [Opn->Bgs]: Old Value kept after unset() on a &$parameter inside function.
| From: | iliaa@php.net | Date: | Wed, 04 Sep 2002 17:25:31 +0000 |
| Subject: | #19146 [Opn->Bgs]: Old Value kept after unset() on a &$parameter inside function. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-18438@lists.php.net to get a copy of this message | ||
ID: 19146
Updated by: iliaa@php.net
Reported By: purodha.blissenbach@hostsharing.net
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Linux, diverse Debian
PHP Version: 4.1.2
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
unset() destroyes the $byname variable, so when it is re-created in the
function it is no longer 'attached' to the $byname that is passed by
reference to the function. Instead it is now a local variable inside
that function.
Previous Comments:
------------------------------------------------------------------------
[2002-08-28 09:17:08] purodha.blissenbach@hostsharing.net
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 this bug report at http://bugs.php.net/?id=19146&edit=1