|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77169 Sorting referenced array messes last index
Submitted: 2018-11-17 22:22 UTC Modified: 2018-11-17 22:43 UTC
From: dropapapa at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: Irrelevant OS: Any
Private report: No CVE-ID: None
 [2018-11-17 22:22 UTC] dropapapa at gmail dot com
When foreaching array of arrays referenced, the last index will remain pointer to the second last index afterwards.

Test script:
$arrays = [
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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-11-17 22:43 UTC]
-Status: Open +Status: Not a bug
 [2018-11-17 22:43 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at
Big red warning.
 [2018-11-17 22:57 UTC] spam2 at rhsoft dot net
your code is broken because it#s missing a unset()
either try to understand what references are or don't use them
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Mar 28 19:01:27 2020 UTC