ID: 8972
User Update by: [EMAIL PROTECTED]
Old-Status: Closed
Status: Open
Bug Type: Scripting Engine problem
Description: Referenced variables and unset()
Dosn't solve my problem and the fact, that PHPs behavior is unuseable doing the thing
I need it for. I have been written
an ugly workarround in PHP to make PHP working like I would expect it to.
During this I found out some other things, so in my eyes it remains as a bug, cause
<?
function test(&$bla) {
unset($bla['hugo']);
$bla['hugo']=3;
}
$bla=Array(
'hugo'=>1,
'huba'=>2
);
test($bla);
print_r($bla);
?>
works as expected (Array ( [huba] => 2 [hugo] => 3 ) - what was the *least* thing I
expected). So PHP works not harmonious with referenced variables, which is really a
thing I cannot use in any way and will by sure cause many unexpected bugs for other
developers - even if they read the documented behaviour for references very carefully.
Please would you be so kind to change the state of this bug (sorry, it IS a bug) to
closed when PHP solves this problem as nearly everybody would expect it to; cause
otherwise there could be the danger, that there will be no chance to change PHPs
behavior, cause everybody expect it to behave like the mentioned bug. :-)
If you don't agree with me, just read the user contributed notes for 'References
Explained'.
Previous Comments:
---------------------------------------------------------------------------
[2001-03-06 08:12:11] [EMAIL PROTECTED]
No, it won't work that way (your first example). Unset
breaks the reference. Please read the "References explained"
part in the manual.
---------------------------------------------------------------------------
[2001-01-28 19:40:52] [EMAIL PROTECTED]
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"?
---------------------------------------------------------------------------
Full Bug description available at: http://bugs.php.net/?id=8972
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]