#47211 [NEW]: Array handling problem

From: Date: Sat, 24 Jan 2009 20:28:56 +0000
Subject: #47211 [NEW]: Array handling problem
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-133197@lists.php.net to get a copy of this message
From: usmanghanee at gmail dot com Operating system: Windows XP (Service Pack 2) PHP version: 5.3.0alpha3 PHP Bug Type: Unknown/Other Function Bug description: Array handling problem 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. */ -- Edit bug report at http://bugs.php.net/?id=47211&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=47211&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=47211&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=47211&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=47211&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=47211&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=47211&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=47211&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=47211&r=needscript Try newer version: http://bugs.php.net/fix.php?id=47211&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=47211&r=support Expected behavior: http://bugs.php.net/fix.php?id=47211&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=47211&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=47211&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=47211&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47211&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=47211&r=dst IIS Stability: http://bugs.php.net/fix.php?id=47211&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=47211&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=47211&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=47211&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=47211&r=mysqlcfg

« previous php.bugs (#133197) next »