Bug #71603 [Opn->Csd]: compact() maintains references in php7

From: Date: Tue, 16 Feb 2016 03:03:29 +0000
Subject: Bug #71603 [Opn->Csd]: compact() maintains references in php7
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199243@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71603&edit=1 ID: 71603 Updated by: laruence@php.net Reported by: tim at zaremedia dot com Summary: compact() maintains references in php7 -Status: Open +Status: Closed Type: Bug Package: Scripting Engine problem Operating System: Debian 8 PHP Version: 7.0.3 Block user comment: N Private report: N New Comment: Automatic comment on behalf of laruence@gmail.com Revision: http://git.php.net/?p=php-src.git;a=commit;h=0fccd154bdb27476289bab18a9112fb7b20ae607 Log: Fixed bug #71603 (compact() maintains references in php7) Previous Comments: ------------------------------------------------------------------------ [2016-02-16 01:16:40] tim at zaremedia dot com I'm not sure if it's better or not but it was a surprising change between the two versions. I'd argue that if this is the "correct" way then: $array2 = ['foo_reference' => $foo_reference]; should also behave in a similar fashion, which it does not. ------------------------------------------------------------------------ [2016-02-16 00:58:02] requinix@php.net PHP 7's changes also fixed references to work more consistently. Isn't the new behavior better? Since the variable was a reference, shouldn't the array use a reference too? ------------------------------------------------------------------------ [2016-02-15 23:24:54] tim at zaremedia dot com Description: ------------ When compact() is used with references, those references are maintained in the new array in php7 and not in 5.6 Test script: --------------- <?php $foo = 45; $foo_reference =& $foo; $array = compact('foo_reference'); print_r($array); $foo = 50; print_r($array); Expected result: ---------------- PHP 5.6.17 ---------- Array ( [foo_reference] => 45 ) Array ( [foo_reference] => 45 ) Actual result: -------------- PHP 7.0.3 --------- Array ( [foo_reference] => 45 ) Array ( [foo_reference] => 50 ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71603&edit=1

« previous php.bugs (#199243) next »