Edit report at https://bugs.php.net/bug.php?id=70127&edit=1
ID: 70127
Updated by: cmb@php.net
Reported by: office at moving-bytes dot at
Summary: var_dump((object)array("123" => new stdclass, "123"
=> "muh"));
Status: Analyzed
Type: Bug
Package: Scripting Engine problem
Operating System: *
PHP Version: 5.6.11
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
The behavior when casting object to array is already well
documented[1]:
> If an object is converted to an array, the result is an array> whose elements are the object's properties. The keys are the> member variable names, with a few notable exceptions: integer> properties are unaccessible; [...]
[1] <http://php.net/manual/en/language.types.array.php#language.types.array.casting>
Previous Comments:
------------------------------------------------------------------------
[2015-07-24 14:07:50] laruence@php.net
I don't think so, it will be overhead while casting or accessing for rarely cases..
just with a good document should be fine.
------------------------------------------------------------------------
[2015-07-24 14:07:49] laruence@php.net
I don't think so, it will be overhead while casting or accessing for rarely cases..
just with a good document should be fine.
------------------------------------------------------------------------
[2015-07-24 14:00:47] bwoebi@php.net
IMHO, we really ought to fix that.
arrays store and access (rightfully, I guess) numeric keys as integers.
objects store and access all the keys as strings.
We maybe should do the same numeric access for dynamic properties on objects...
------------------------------------------------------------------------
[2015-07-24 13:40:21] office at moving-bytes dot at
imho this is a bug, since this is a complete inconsistent behavior:
example from stackoverflow:
$a = array('123' => '123');
$o1 = (object)$a;
$o2 = new stdClass;
$o2->{'123'} = '123'; // setting property is OK
echo $o1->{'123'}; // error!
echo $o2->{'123'}; // works... WTF?
http://stackoverflow.com/questions/10333016/how-to-access-object-properties-with-names-like-integers/10333200#10333200
------------------------------------------------------------------------
[2015-07-24 13:05:44] cmb@php.net
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions. Due to the volume
of reports we can not explain in detail here why your report is not
a bug. The support channels will be able to provide an explanation
for you.
Thank you for your interest in PHP.
It is possible to have numeric property names by other means:
$o = new StdClass();
$o->{123} = 'foo';
var_dump($o);
This is a feature, and not a bug.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=70127
--
Edit this bug report at https://bugs.php.net/bug.php?id=70127&edit=1