Bug #69165 [Opn->Nab]: Passing result of assignation by reference

From: Date: Sat, 09 Dec 2017 14:08:12 +0000
Subject: Bug #69165 [Opn->Nab]: Passing result of assignation by reference
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213030@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69165&edit=1 ID: 69165 Updated by: nikic@php.net Reported by: contact at jubianchi dot fr Summary: Passing result of assignation by reference -Status: Open +Status: Not a bug Type: Bug Package: Variables related PHP Version: master-Git-2015-03-02 (Git) Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2015-03-03 07:28:15] nikic@php.net The old behavior looks like a bug to me. Assignments always return the (dereferenced) RHS *value*. ------------------------------------------------------------------------ [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

« previous php.bugs (#213030) next »