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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: Jones at miliz dot org
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 21:01:35 2025 UTC