Bug #70127 [Ana]: var_dump((object)array("123" => new stdclass, "123" => "muh"));

From: Date: Fri, 24 Jul 2015 15:26:10 +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-194683@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:         bwoebi@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
 Block user comment: N
 Private report:     N

 New Comment:

@laruence: note that the overhead will only exist for dynamic property accesses (non-CONST VM
operand and only on a dynamic access - meaning when there is no fast access to property table).
Which should be a rare enough case … and that particular case is already relatively slow.

I think we could afford it?


Previous Comments:
------------------------------------------------------------------------
[2015-07-24 14:22:34] cmb@php.net

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>

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

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


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


Thread (1 message)

  • bwoebi@php.net
  • Unknown Message
    • bwoebi@php.net
« previous php.bugs (#194683) next »