Bug #71529 [NEW]: Variable references on array elements don't work when using count
| From: | David dot Gausmann at measX dot com | Date: | Fri, 05 Feb 2016 08:55:40 +0000 |
| Subject: | Bug #71529 [NEW]: Variable references on array elements don't work when using count | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-199062@lists.php.net to get a copy of this message | ||
From: David dot Gausmann at measX dot com
Operating system: irrelevant
PHP version: 7.0.3
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Variable references on array elements don't work when using count
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.)
--
Edit bug report at https://bugs.php.net/bug.php?id=71529&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71529&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71529&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71529&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71529&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71529&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71529&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71529&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71529&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71529&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71529&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71529&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71529&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71529&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71529&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71529&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71529&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71529&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71529&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71529&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71529&r=mysqlcfg