Req #30288 [Opn->Wfx]: Problems making a variable a reference which was passed by reference
| From: | nikic@php.net | Date: | Sun, 17 Feb 2013 13:36:50 +0000 |
| Subject: | Req #30288 [Opn->Wfx]: Problems making a variable a reference which was passed by reference | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-176686@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=30288&edit=1
ID: 30288
Updated by: nikic@php.net
Reported by: Jones at miliz dot org
Summary: Problems making a variable a reference which was
passed by reference
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
Operating System: Linux
PHP Version: 4.3.9
Block user comment: N
Private report: N
New Comment:
Assigning by-reference to a variable that already is a reference will break the existing reference.
What you want is write "$second = $source" instead of "$second =& $source".
This will fix your issue.
Previous Comments:
------------------------------------------------------------------------
[2004-09-30 11:04:51] Jones at miliz dot org
Description:
------------
Making a variable, which was passed by reference, a reference to another variable inside the
function won't work outside this function
Reproduce code:
---------------
<?php
function &testReference(&$first, &$second) {
$source = 'my Test';
$first = $source;
$second =& $source;
var_dump($second);
return $second;
}
$ref3 =& testReference($ref1, $ref2);
var_dump($ref1);
var_dump($ref2);
var_dump($ref3);
?>
Expected result:
----------------
string(7) "my Test"
string(7) "my Test"
string(7) "my Test"
string(7) "my Test"
Actual result:
--------------
string(7) "my Test"
string(7) "my Test"
NULL
string(7) "my Test"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=30288&edit=1