PHP 4.0 Bug #8972 Updated: Referenced variables and unset()
| From: | stas@php.net | Date: | Tue, 06 Mar 2001 13:12:11 +0000 |
| Subject: | PHP 4.0 Bug #8972 Updated: Referenced variables and unset() | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-48034@lists.php.net to get a copy of this message | ||
ID: 8972
Updated by: stas
Reported By: aulbach@unter.franken.de
Old-Status: Open
Status: Closed
Bug Type: Scripting Engine problem
Assigned To:
Comments:
No, it won't work that way (your first example). Unset
breaks the reference. Please read the "References explained"
part in the manual.
Previous Comments:
---------------------------------------------------------------------------
[2001-01-28 19:40:52] aulbach@unter.franken.de
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"?
---------------------------------------------------------------------------
ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at http://bugs.php.net/?id=8972&edit=2