Bug #70127 [Ana]: var_dump((object)array("123" => new stdclass, "123" => "muh"));
| From: | laruence@php.net | Date: | Fri, 24 Jul 2015 14:07:50 +0000 |
| Subject: | Bug #70127 [Ana]: var_dump((object)array("123" => new stdclass, "123" => "muh")); | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-194678@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70127&edit=1
ID: 70127
Updated by: laruence@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:
I don't think so, it will be overhead while casting or accessing for rarely cases..
just with a good document should be fine.
Previous Comments:
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
[2015-07-24 12:40:21] office at moving-bytes dot at
Description:
------------
Usually its not possible to create class and variablenames containing only numbers.
But if you create an array and typecast it to object, these rules does not exist anymore.
Test script:
---------------
var_dump((object)array("123" => new stdclass, "123" => "muh"));
Expected result:
----------------
PHP Parse error: syntax error, unexpected '123' (T_LNUMBER), expecting identifier
(T_STRING)
Actual result:
--------------
object(stdClass)#1 (1) {
[123]=>
string(3) "foo"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70127&edit=1