|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-01-04 22:24 UTC] jwege at gmx dot net
Description: ------------ --- From manual page: http://www.php.net/function.array-shift#refsect1-function.array-shift-seealso --- Having an associative array where the keys are number-strings (enclosed in quotes as strings - see example), this strings get converted into numbers when using array_shift(). This is a severe bug! Test script: --------------- $a["_"] = "blank dummy"; $a["01"] = "one"; $a["10"] = "ten"; $a["20"] = "twenty"; print_r( $a ); echo $a["10"] . "\n"; array_shift( $a ); print_r( $a ); echo $a["10"] . "\n"; // THIS PRODUCES AN UNDEFINED INDEX ERROR echo $a["20"] . "\n"; // THIS PRODUCES AN UNDEFINED INDEX ERROR echo $a[0] . "\n"; // THIS SHOULD PRODUCE AN ERROR BUT SHOWS THE VALUE echo $a[1] . "\n"; // THIS SHOULD PRODUCE AN ERROR BUT SHOWS THE VALUE Expected result: ---------------- I expect that the line echo $a["10"] . "\n"; will produce "ten" as an output, also echo $a["20"] . "\n"; should output "twenty". Actual result: -------------- Notice: Undefined index: 10 in [test] on line 13 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 05:00:01 2025 UTC |
`array_shift` has nothing to do with this. Keys are integers immedietly after assignment. Use `var_dump` instad of `print_r`. This behaviour is consistent with documentation. [1] clearly states that: "If a key is the standard representation of an integer, it will be interpreted as such." [1] http://pl.php.net/manual/en/language.types.array.php