Bug #74653 [Opn->Nab]: foreach with reference and the ?: operator

From: Date: Thu, 25 May 2017 18:40:06 +0000
Subject: Bug #74653 [Opn->Nab]: foreach with reference and the ?: operator
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209260@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74653&edit=1 ID: 74653 Updated by: requinix@php.net Reported by: david+php at porkrind dot org Summary: foreach with reference and the ?: operator -Status: Open +Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: Ubuntu PHP Version: 7.1.5 Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php http://php.net/manual/en/migration70.incompatible.php#migration70.incompatible.foreach $a['hello'] ?: [] is an expression so the PHP 5 behavior was incorrect to begin with. Previous Comments: ------------------------------------------------------------------------ [2017-05-25 18:19:12] david+php at porkrind dot org Description: ------------ In php 5.5, using the ?: operator in reference based foreach loops worked. In php 7.1 the reference doesn't affect the original array any more. Test script: --------------- <?php $a=['hello' => [1,2,3]]; foreach ($a['hello'] ?: [] as &$x) $x++; print_r($a); Expected result: ---------------- In PHP 5.5 and PHP 5.6 the output is: Array ( [hello] => Array ( [0] => 2 [1] => 3 [2] => 4 ) ) Actual result: -------------- In PHP 7.1 the output is: Array ( [hello] => Array ( [0] => 1 [1] => 2 [2] => 3 ) ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74653&edit=1

« previous php.bugs (#209260) next »