php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46774 Arrays Coerced to Objects, Property Problems
Submitted: 2008-12-06 03:02 UTC Modified: 2009-01-22 01:07 UTC
Votes:5
Avg. Score:3.2 ± 0.7
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:3 (100.0%)
From: deligo2003 at yahoo dot ca Assigned:
Status: Not a bug Package: Reflection related
PHP Version: 5.2.7 OS: Ubuntu
Private report: No CVE-ID: None
 [2008-12-06 03:02 UTC] deligo2003 at yahoo dot ca
Description:
------------
var_export(), get_object_vars(), and ReflectionObject do not recognize or handle object properties correctly that are coerced from a numerically indexed array or an array with string keys of any integer except for zero.

ie: (object)array(1,2,3,4);
ie: (object)array('1' => 1, '-5' => 2, '3' => 3, '-10' => 4);

Values seem to have no effect. There may be other functions/classes that do not handle these types of property names correctly. The samples included only show the results of ReflectionObject::getProperties(), but also functions like ReflectionObject::hasProperty() incorrectly returns false, for example.

Reproduce code:
---------------
<?php
$a = (object)array(1, 2, 3, 4);
echo '<pre>';
var_dump($a);
print_r($a);
var_export($a);
print_r(get_object_vars($a));
$r = new ReflectionObject($a);
print_r($r->getProperties());
?>

Expected result:
----------------
var_export($a);
output: stdClass::__set_state(array(1,2,3,4))

print_r(get_object_vars($a));
output: Array([0]=>1,[1]=>2,[2]=>3,[3]=>4)

print_r($r->getProperties());
output:
Array(
    [0]=>ReflectionProperty Object (
        [name]=>0
        [class]=>stdClass
    )
    ... and so on up to [3]
)

Actual result:
--------------
var_export($a);
output: stdClass::__set_state(array())

print_r(get_object_vars($a));
output: Array()

print_r($r->getProperties());
output:
    note: this result varies

ie1:

Array
(
    [0] => ReflectionProperty Object
        (
            [name] => ?.C?6??Xl??Ћ??*?v\?#?I?I
            [class] => stdClass
        )

    [1] => ReflectionProperty Object
        (
            [name] => M??F?Xl??Ћ??
            [class] => stdClass
        )

)

ie2:

Array
(
    [0] => ReflectionProperty Object
        (
            [name] => F7??5?h?? ??oMWM=[?*?"?I
            [class] => stdClass
        )

)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-06 03:06 UTC] deligo2003 at yahoo dot ca
When I said "except for zero." I really meant "except for an integer starting with zero".

ie: 1234 will reproduce the error but 0123 will not.

For negative integers -1234 will reproduce the error but -0123 will not, and neither will 0-123

Sorry for not stating this correctly in the first place.
 [2008-12-31 16:32 UTC] felipe@php.net
This is a known issue, and was documented:
See bug #45959
 [2009-01-22 01:07 UTC] jani@php.net
So this is duplicate -> Bogus..
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Mar 22 14:01:26 2019 UTC