From: mazsolt at yahoo dot com
Operating system: Win
PHP version: 5.2.1
PHP Bug Type: Class/Object related
Bug description: array conversion to object
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 bug report at http://bugs.php.net/?id=41095&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=41095&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=41095&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=41095&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=41095&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=41095&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=41095&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=41095&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=41095&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=41095&r=support
Expected behavior: http://bugs.php.net/fix.php?id=41095&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=41095&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=41095&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=41095&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41095&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=41095&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=41095&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=41095&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=41095&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=41095&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=41095&r=mysqlcfg