|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69165 Passing result of assignation by reference
Submitted: 2015-03-02 23:48 UTC Modified: 2017-12-09 14:08 UTC
From: contact at jubianchi dot fr Assigned:
Status: Not a bug Package: Variables related
PHP Version: master-Git-2015-03-02 (Git) OS:
Private report: No CVE-ID: None
 [2015-03-02 23:48 UTC] contact at jubianchi dot fr
There seems to be a bug when passing the result of an assignation to a function expecting a reference.

I extracted a snippet from atoum where we use a trick to verify if a variable is a reference to another and saw from the tests that PHP7's behavior changed

Test script:


function cmp(& $reference, & $value) {
    $tmp = $reference;
	$reference = uniqid(mt_rand());
	$isReference = ($value === $reference);
	$reference = $tmp;  
	return $isReference;

$value = uniqid();
$reference = & $value;
var_dump(cmp($reference, $value));

$value = new \exception();
var_dump(cmp($reference, $value));

var_dump(cmp($reference, $value = new \exception()));

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-03 07:28 UTC]
The old behavior looks like a bug to me. Assignments always return the (dereferenced) RHS *value*.
 [2017-12-09 14:08 UTC]
-Status: Open +Status: Not a bug
 [2017-12-09 14:08 UTC]
Per previous comment, I believe the new behavior is correct, so I'm closing this. There used to be an exemption for passing objects by-ref due to this being common in PHP 4, but this special case no longer exists.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 23 21:01:28 2024 UTC