ID:               45346
 Updated by:       [EMAIL PROTECTED]
 Reported By:      xavier dot pinard at laposte dot net
-Status:           Open
+Status:           Bogus
 Bug Type:         Arrays related
 Operating System: WIN XP
 PHP Version:      5.2.6
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php




Previous Comments:
------------------------------------------------------------------------

[2008-09-30 13:05:43] xavier dot pinard at laposte dot net

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

------------------------------------------------------------------------

[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-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

Reply via email to