|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2016-02-05 10:20 UTC] inefedor at gmail dot com
  [2016-02-06 15:45 UTC] nikic@php.net
  [2016-02-06 15:45 UTC] nikic@php.net
 
-Status: Open
+Status: Closed
  [2016-02-06 15:58 UTC] nikic@php.net
  [2016-07-20 11:33 UTC] davey@php.net
 | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 06:00:01 2025 UTC | 
Description: ------------ In a websites code we have got nested arrays for a tree structure. In PHP 5.5 that code worked fine, but since PHP 7 it doesn't work anymore. I've read the "backward incompatibility changes", but this point seems not to be listed there (and in my opinion it is a bug). In my code I am pushing variables by-reference into an stack array. The references are referencing to the last element of another entry of the stack array. The bug seems to depend on the usage of count(). If I use fixed indices for testing purposes, then the code works fine. Test script: --------------- <?php $avOutput = array('test' => array()); $avStack = array(&$avOutput['test']); $avTemp = array('data' => 1, 'test' => array()); $avStack[count($avStack) - 1][] = $avTemp; $avStack[] = &$avStack[count($avStack) - 1][count($avStack[count($avStack) - 1]) - 1]['test']; // WORKS NOT in PHP7 (but worked in PHP 5.5) //$avStack[] = &$avStack[0][0]['test']; // WORKS $avTemp = array('data' => 2, 'test' => array()); $avStack[count($avStack) - 1][] = $avTemp; echo "<xmp>"; print_r($avOutput); echo "</xmp>"; ?> Expected result: ---------------- Array ( [test] => Array ( [0] => Array ( [data] => 1 [test] => Array ( [0] => Array ( [data] => 2 [test] => Array ( ) ) ) ) ) ) (You can see that [data] => 1 and [data] => 2 are both listed. This was the result in PHP 5.5) Actual result: -------------- Array ( [test] => Array ( [0] => Array ( [data] => 1 [test] => Array ( ) ) ) ) (You can see that [data] => 1 is there, but [data] => 2 is missing. If you uncomment the line with fixed indices, you become the correct result. If you output the result of the both count(), you will get 0 for each, so both lines should be equal.)