Bug #74653 [NEW]: foreach with reference and the ?: operator

From: Date: Thu, 25 May 2017 18:19:18 +0000
Subject: Bug #74653 [NEW]: foreach with reference and the ?: operator
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209259@lists.php.net to get a copy of this message
From: david+php at porkrind dot org Operating system: Ubuntu PHP version: 7.1.5 Package: Scripting Engine problem Bug Type: Bug Bug description:foreach with reference and the ?: operator 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 bug report at https://bugs.php.net/bug.php?id=74653&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74653&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74653&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74653&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=74653&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=74653&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=74653&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=74653&r=needscript Try newer version: https://bugs.php.net/fix.php?id=74653&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=74653&r=support Expected behavior: https://bugs.php.net/fix.php?id=74653&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=74653&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=74653&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=74653&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74653&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=74653&r=dst IIS Stability: https://bugs.php.net/fix.php?id=74653&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=74653&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=74653&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=74653&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=74653&r=mysqlcfg

« previous php.bugs (#209259) next »