php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #30288 Problems making a variable a reference which was passed by reference
Submitted: 2004-09-30 11:04 UTC Modified: 2013-02-17 13:36 UTC
From: Jones at miliz dot org Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 4.3.9 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2004-09-30 11:04 UTC] 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"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-17 13:36 UTC] nikic@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 [2013-02-17 13:36 UTC] nikic@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 11:01:29 2024 UTC