|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-03-30 20:38 UTC] nikic@php.net
-Status: Open
+Status: Duplicate
[2016-03-30 20:38 UTC] nikic@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 10:00:01 2025 UTC |
Description: ------------ We're currently upgrading to PHP7, and noticed a notice which wasn't present in PHP5. In PHP5 there is a warning regarding modification of the array, due to the reference to $sortingData. In PHP7 however, an offset is missing. Strangely, when var_dump'ing the indexes of the array, the 0 index is present. Test script: --------------- <?php ini_set('display_errors', true); error_reporting(E_ALL); $sortingData = [ 0 => 10, 1 => 12, // This key is magic - anything >= 8 (or a non-integer key) makes this script produce the E_NOTICE 8 => 11, ]; uksort($sortingData, function ($a, $b) use (&$sortingData) { return $sortingData[$a] > $sortingData[$b] ? -1 : 1; }); var_dump($sortingData); Expected result: ---------------- Warning: uksort(): Array was modified by the user comparison function in /home/richard/break.php on line 15 array(3) { [1]=> int(12) [8]=> int(11) [0]=> int(10) } Actual result: -------------- Notice: Undefined offset: 0 in /home/richard/break.php on line 14 array(3) { [1]=> int(12) [8]=> int(11) [0]=> int(10) }