Bug #71603 [Fbk->Opn]: compact() maintains references in php7
| From: | tim at zaremedia dot com | Date: | Tue, 16 Feb 2016 01:16:41 +0000 |
| Subject: | Bug #71603 [Fbk->Opn]: compact() maintains references in php7 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-199240@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
User updated by: tim at zaremedia dot com
Reported by: tim at zaremedia dot com
Summary: compact() maintains references in php7
-Status: Feedback
+Status: Open
Type: Bug
Package: Scripting Engine problem
Operating System: Debian 8
PHP Version: 7.0.3
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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