Bug #77169 [Com]: Sorting referenced array messes last index

From: Date: Sat, 17 Nov 2018 22:57:45 +0000
Subject: Bug #77169 [Com]: Sorting referenced array messes last index
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-218004@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77169&edit=1 ID: 77169 Comment by: spam2 at rhsoft dot net Reported by: dropapapa at gmail dot com Summary: Sorting referenced array messes last index Status: Not a bug Type: Bug Package: Arrays related Operating System: Any PHP Version: Irrelevant Block user comment: N Private report: N New Comment: your code is broken because it#s missing a unset() either try to understand what references are or don't use them https://schlueters.de/blog/archives/180-References-Still-bad-in-PHP-7.html Previous Comments: ------------------------------------------------------------------------ [2018-11-17 22:43:08] requinix@php.net 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/control-structures.foreach.php Big red warning. ------------------------------------------------------------------------ [2018-11-17 22:22:10] dropapapa at gmail dot com Description: ------------ When foreaching array of arrays referenced, the last index will remain pointer to the second last index afterwards. Test script: --------------- <?php $arrays = [ [1,3,2], [2,8,3], [10,8,9], ]; foreach ($arrays as &$array) { echo 'First: ' . implode(', ', $array) . PHP_EOL; } $arrays[1] = [3,3,3]; foreach ($arrays as $array) { echo 'Second: ' . implode(', ', $array) . PHP_EOL; } Expected result: ---------------- Last index would act same way the others do. Actual result: -------------- Last index is now reference to second last index. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77169&edit=1

« previous php.bugs (#218004) next »