ID:               41095
 Updated by:       [EMAIL PROTECTED]
 Reported By:      mazsolt at yahoo dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Class/Object related
 Operating System: Win
 PHP Version:      5.2.1
 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

$obj->{0} should help. See documentation for more information.


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

[2007-04-15 17:19:39] mazsolt at yahoo dot com

Description:
------------
I tried to convert an array, with integer keys, to an object. The
problem seems to be that conversion is done, but the object's elements
can't be called by the script. 

$obj = (object)array(1,2,3);
var_dump($obj) returns: object(stdClass)#1 (3) { [0]=> int(1) [1]=>
int(2) [2]=> int(3) 
var_export($obj) returns:  stdClass::__set_state(array( ))

OK, the conversion is done, but objects don't support $obj->0 property
access (property names should be valid php identifiers). 
When it's not a bug, is there a way to call that property? 
Except the object iteration pattern? I consulted some forums, but
nowhere have got an answer.

Reproduce code:
---------------
$obj = (object)array(1,2,3);

// it works
foreach($obj as $key => $value) {
    echo "$key => $value";
}

// doesn't work
echo $obj->0;



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


-- 
Edit this bug report at http://bugs.php.net/?id=41095&edit=1

Reply via email to