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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

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: Fri Apr 26 15:01:56 2024 UTC