PHP 4.0 Bug #8115 Updated: variable passed by reference incorrectly handled
| From: | stas@php.net | Date: | Tue, 05 Dec 2000 11:33:46 +0000 |
| Subject: | PHP 4.0 Bug #8115 Updated: variable passed by reference incorrectly handled | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-40111@lists.php.net to get a copy of this message | ||
ID: 8115
Updated by: stas
Reported By: christian@architech.no
Status: Closed
Bug Type: Scripting Engine problem
Assigned To:
Comments:
This is exactly as it is meant to work. Please read
"References explained" in the manual. When you do the unset,
you effectively destroy local variable $a, breaking the
reference. Now when you mention $a again, it's not
referenced to $my_var anymore - it's a new variable.
Previous Comments:
---------------------------------------------------------------------------
[2000-12-05 06:27:46] christian@architech.no
It concerns variables passed by reference... and the unset() function.
# Let's define a very simple function that converts an array to a string :
function foo(&$a)
{
$an_array = array("abcdef");
unset($a);
for ($i=0; $i<sizeof($an_array); $i++)
$a = $a . $an_array[$i];
}
# and call it :
foo($my_var);
# $my_var is NOT EQUAL TO "abcdef" !!!!!
However it works fine when we don't try to unset the $a variable. (replacing the line with $a =
"").
---------------------------------------------------------------------------
Full Bug description available at: http://bugs.php.net/?id=8115