Bug #69165 [Com]: Passing result of assignation by reference
Edit report at https://bugs.php.net/bug.php?id=69165&edit=1
ID: 69165
Comment by: nikic@php.net
Reported by: contact at jubianchi dot fr
Summary: Passing result of assignation by reference
Status: Open
Type: Bug
Package: Variables related
PHP Version: master-Git-2015-03-02 (Git)
Block user comment: N
Private report: N
New Comment:
The old behavior looks like a bug to me. Assignments always return the (dereferenced) RHS *value*.
Previous Comments:
------------------------------------------------------------------------
[2015-03-02 23:48:33] contact at jubianchi dot fr
Description:
------------
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:
---------------
<?php
// http://3v4l.org/UrMbA
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:
----------------
bool(true)
bool(true)
bool(true)
Actual result:
--------------
bool(true)
bool(true)
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69165&edit=1
Thread (3 messages)