ID: 45346 User updated by: xavier dot pinard at laposte dot net Reported By: xavier dot pinard at laposte dot net -Status: No Feedback +Status: Open Bug Type: Arrays related Operating System: WIN XP PHP Version: 5.2.6 New Comment:
Hi, Sorry for embedding huge scripts into the report. I submit you the new test code with open and close tags : <?php $stdclass = neW StdcLaSs() ; $stdclass->{0} = 'index0' ; $stdclassElement = (arRaY)$stdclass ; $var = array_keys( $stdclassElement ) ; $key = $var [ 0 ] ; Echo '$stdclassElement[ $key ] :: ' , $stdclassElement[ $key ] , '$stdclassElement[0] :: ' , $stdclassElement[ 0 ] , '$stdclassElement["0"] :: ', $stdclassElement['0'] ; ?> Hope it's gonna be more useful. Do I have to submit the bug again under a new Id or it's gonna be find like that ? Regards, Xavier Previous Comments: ------------------------------------------------------------------------ [2008-09-12 22:50:28] steven at acko dot net Here is a minimal test case: <?php $obj = new stdClass(); $obj->{0} = 'foo'; $obj->{'1'} = 'bar'; $obj->{'x'} = 'baz'; $array = (array)$obj; var_dump($array[0]); var_dump($array['1']); var_dump($array['x']); ?> Expected result: --------------- string(3) "foo" string(3) "bar" string(3) "baz" Actual result: -------------- NULL NULL string(3) "baz" If you compare var_dump((array)$obj) as defined above with var_dump(array(0 => 'foo', '1' => 'bar', 'x' => 'baz')), you can see that the numeric array keys are stored as strings rather than integers, which causes the array lookups to fail. (PS: The above developer's response reads like a standard copy/paste reply that ignores the fact that example code was already supplied. If the example was insufficient or unclear, at least take 5 seconds to explain why. The way this bug report is now, it does not help anyone.) ------------------------------------------------------------------------ [2008-07-19 01:00:01] php-bugs at lists dot php dot net No feedback was provided for this bug for over a week, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open". ------------------------------------------------------------------------ [2008-07-11 16:01:35] [EMAIL PROTECTED] Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If the script requires a database to demonstrate the issue, please make sure it creates all necessary tables, stored procedures etc. Please avoid embedding huge scripts into the report. ------------------------------------------------------------------------ [2008-06-24 10:30:06] xavier dot pinard at laposte dot net Description: ------------ object numeric's name properties are cast in string array's index. created indexes becomes not accessible. Reproduce code: --------------- #5.2.7.-DEV on 2007-06-24 # WANTED => cast object to array and access first element with 0 index #RESULT => the array key with the index '0' is nor accessible by 0 or "0", uncool ... #¿PROBLEM? => Shouldn't the array key needs to be numeric instead of a string after object to array cast ? $stdclass = neW StdcLaSs() ; $stdclass->{0} = 'index0' ; $stdclassElement = (arRaY)$stdclass ; $var = array_keys( $stdclassElement ) ; $key = $var [ 0 ] ; Echo '$stdclassElement[ $key ] :: ' , $stdclassElement[ $key ] , '$stdclassElement[0] :: ' , $stdclassElement[ 0 ] , '$stdclassElement["0"] :: ', $stdclassElement['0'] ; Expected result: ---------------- acess neither to array index '0' by [0] or ["0"] Actual result: -------------- the index is not accessible ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45346&edit=1