|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-01-24 23:07 UTC] johannes@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 14:00:01 2025 UTC |
Description: ------------ I don't know exactly how to explain it. Forgive me if I use wrong English. I'll try to be as short as possible. I tried to use two dimensional array and faced a strange problem. Problem Brief: First I defined two dimensional array. Then, I tried to access a third dimension of such array which was not actually defined at all. The result should have been a warning saying something like "Undefined index" but it printed out some value. The value printed was the first letter of the value at 2nd dimension based offset. Initially, I tried different(variety of) alphabetic and alphanumeric values at third level dimension. It kept on printing the first letter of the value as mentioned above. Then, I tried purely numeric values like '0', '1', '2' and so on. This time it behaved differently. It printed out the letter at offset number, provided as third dimension, from the value at 2nd dimension. I tested it with 5.2.8 and 5.3.0Alpha both. The problem also exists in version 5.3.0Alpha. I also tried the command line methods for both versions which resulted out in the same way. Reproduce code: --------------- $arr = array("sub1" => array("sub2" => "SomeString")); /* // I also tried it as the code given in these comments. // It gave the same output. $arr["sub1"] = array(); $arr["sub1"]["sub2"] = "SomeString"; */ echo $arr["sub1"]["sub2"]["sub3"]; Expected result: ---------------- There should have been some warning saying "Undefined index - sub3". Actual result: -------------- The actual result was an "S" printed on the screen, the first letter of the value "SomeString". /* Please Note: ------------ 1) When I provided '0' instead of "sub3" as the third dimension for echo purpose, it printed out "S" which is the letter at offset '0' of the value "SomeString". 2) When I provided '1' instead of "sub3" as the third dimension for echo purpose, it printed out "o" which is the letter at offset '1' of the value "SomeString". 3) When I provided '2' instead of "sub3" as the third dimension for echo purpose, it printed out "m" which is the letter at offset '2' of the value "SomeString". 4) So on. */