PHP 4.0 Bug #8972: Referenced variables and unset()
| From: | aulbach at unter dot franken dot de | Date: | Mon, 29 Jan 2001 00:40:52 +0000 |
| Subject: | PHP 4.0 Bug #8972: Referenced variables and unset() | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-45232@lists.php.net to get a copy of this message | ||
From: aulbach@unter.franken.de
Operating system: Linux
PHP version: 4.0.3pl1
PHP Bug Type: Scripting Engine problem
Bug description: Referenced variables and unset()
I found another bug (see id #8937) in connection with unset(). [Unset dosn´t work properly since
august 1999]
<?
function test(&$bla) {
unset($bla);
$bla="huhu";
}
$bla="HIHI";
test($bla);
echo $bla;
?>
This will return "HIHI" instead of an expected "" or "huhu".
This bug exists cause unset() unsets the reference to $bla, not $bla itself. This also depends the
GLOBAL-statement (see #8937)!
This is a bug, cause it is against the PHP-concept of making no big difference between reference and
value
[ $bla=1; $hugo=&$bla; $hugo=2 is in the sight of $bla the same as $bla=1; $bla=2; ]
If I want to delete &$bla the correct expression is unset(&$bla). unset($bla) has always to
delete the value
and all references to it. (that's just my opinion :-)
A fix of this bug will produce some compatibility problems with scripts, which has been written into
PHP4 (cause the bug is very old).
But a fix should be done, cause many developers won't mind, that unseting a reference is in the
sight of PHP a completly other thing than unseting a value.
There should be no/very less problems with upgrading PHP3-scripts.
PS: Just a small thought. In autumn last year I programmed constructs like the following
<?
$bla=array(1,array(1,array(1,2,3),3),3);
$ref=&$bla[2][2];
unset($ref);
?>
And I wondered, that this won't work as expected. Now I know why.
A correct solution would be to unset the inner array(1,2,3) and $ref... any other behaviour will
break the mentioned handling of PHP.
Thougth 2:
<?
$bla="HIHI";
$ref=&$bla;
unset($ref);
$ref="huhu";
?>
What is the correct value of $bla. "" (empty) or "huhu"?
--
Edit Bug report at: http://bugs.php.net/?id=8972&edit=1