|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-10-26 17:20 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
-Package: Unknown/Other Function
+Package: Arrays related
[2021-10-26 17:20 UTC] requinix@php.net
[2021-11-04 14:06 UTC] friedrich dot lucas at os-cillation dot de
[2021-11-04 17:30 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 16:00:01 2025 UTC |
Description: ------------ ksort generate different results with the same keys in two arrays under php with the version 8 or higher. This case do only occurs in special conditions: array element count, '0' for array key must exists. ----- No specific php setup. Test script: --------------- // define arrays with the same keys - different key order ('4' and '@' are swapped) $array_at = [ '_' => '', 'Y' => '', '0' => '', '+' => '', 'X' => '', 'W' => '', '1' => '', '3' => '', '@' => '', '4' => '', '5' => '', 'P' => '', 'O' => '', 'N' => '', 'M' => '', 'L' => '', 'K' => '', ]; $array_fr = [ '_' => '', 'Y' => '', '0' => '', '+' => '', 'X' => '', 'W' => '', '1' => '', '3' => '', '4' => '', '@' => '', '5' => '', 'P' => '', 'O' => '', 'N' => '', 'M' => '', 'L' => '', 'K' => '', ]; ksort($array_at); // sort by key ksort($array_fr); // sort by key // expects the same key at the sorted array first position var_dump(array_slice($array_at, 0, 1)); // result: [0 => '''], but only '0' is defined as a key var_dump(array_slice($array_fr, 0, 1)); // result: ['+' => '' ] Expected result: ---------------- The same keysort output from array_at and array_fr. (correct output with php7.x) array(1) { ["+"]=> string(0) "" } array(1) { ["+"]=> string(0) "" } Actual result: -------------- (wrong output with php8.x) array(1) { ["+"]=> string(0) "" } array(1) { [0]=> string(0) "" }