#49154 [Csd]: Corrupted reflection information when object property is numeric
| From: | william dot bailey at cowboysfromhell dot co dot uk | Date: | Wed, 05 Aug 2009 09:28:28 +0000 |
| Subject: | #49154 [Csd]: Corrupted reflection information when object property is numeric | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-140675@lists.php.net to get a copy of this message | ||
ID: 49154
User updated by: william dot bailey at cowboysfromhell dot co dot uk
Reported By: william dot bailey at cowboysfromhell dot co dot uk
Status: Closed
Bug Type: Reflection related
PHP Version: 5.3.0
New Comment:
I agree that 56 from a user defined class perspective is an invalid
property name. However for anonymous or dynamic classes we have a number
of ways to create numeric, and I assume other invalid properties on an
object.
If a property can be created, even if its invalid then surely it should
be visible using reflection otherwise it will only confuse people as the
output from a simple var_dump will not match what reflection will
return.
From the top of my head invalid properties can be created in the
following ways...
<?php
$o = json_decode('{"foo":"bar","56":"FitfySix"}');
var_dump($o);
$o = (object) array("foo"=>"bar","56"=>"FiftySix");
var_dump($o);
$o = new stdClass();
$o->foo = 'bar';
$o->{56} = 'FiftySix';
var_dump($o);
$n = 56;
$o = new stdClass();
$o->foo = 'bar';
$o->$n = 'FiftySix';
var_dump($o);
Previous Comments:
------------------------------------------------------------------------
[2009-08-04 14:59:23] jani@php.net
Already fixed in svn. And it will only return 2 properties. '56' is not
valid property name.
------------------------------------------------------------------------
[2009-08-04 14:45:25] william dot bailey at cowboysfromhell dot co dot
uk
Description:
------------
Reflection information returned by ReflectionObject::getProperties() is
corrupt when an object has numeric properties.
Reproduce code:
---------------
<?php
function d($o)
{
print get_class($o).PHP_EOL.PHP_EOL;
$r = new ReflectionObject($o);
foreach($r->getProperties() as $p)
{
var_dump($p);
print 'Name (HEX): '. bin2hex($p->getName()).PHP_EOL;
print PHP_EOL.PHP_EOL;
}
}
d((object) array('foo'=>'zero', '56'=>'one',
'bar'=>'two'));
Expected result:
----------------
stdClass
object(ReflectionProperty)#3 (2) {
["name"]=>
string(3) "foo"
["class"]=>
string(8) "stdClass"
}
Name (HEX): 666f6f
object(ReflectionProperty)#4 (2) {
["name"]=>
string(2) "56"
["class"]=>
string(8) "stdClass"
}
Name (HEX): 3536
object(ReflectionProperty)#5 (2) {
["name"]=>
string(3) "bar"
["class"]=>
string(8) "stdClass"
}
Name (HEX): 626172
Actual result:
--------------
stdClass
object(ReflectionProperty)#3 (2) {
["name"]=>
string(3) "foo"
["class"]=>
string(8) "stdClass"
}
Name (HEX): 666f6f
object(ReflectionProperty)#4 (2) {
["name"]=>
string(9) "rties() !"
["class"]=>
string(8) "stdClass"
}
Name (HEX): 727469657328292021
object(ReflectionProperty)#5 (2) {
["name"]=>
string(3) "bar"
["class"]=>
string(8) "stdClass"
}
Name (HEX): 626172
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=49154&edit=1