php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73657 Reflection property can't access to ArrayObject property
Submitted: 2016-12-05 17:00 UTC Modified: 2020-02-28 15:15 UTC
From: ilya at antipenko dot pp dot ua Assigned: nikic (profile)
Status: Closed Package: Reflection related
PHP Version: 7.0.13 OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
30 - 24 = ?
Subscribe to this entry?

 
 [2016-12-05 17:00 UTC] ilya at antipenko dot pp dot ua
Description:
------------
Hello.

ReflectionObject::getProperties() returns property which added to ArrayObject with offsetSet(), but this property can't be gotten by ReflectionProperty::getValue().

See https://3v4l.org/Y2CkO

Test script:
---------------
<?php

class A extends \ArrayObject {}

$a = new A;
$a->offsetSet('test', 'testValue');

$reflection = new \ReflectionObject($a);
$properties = $reflection->getProperties();

$c = count($properties);

echo $c . PHP_EOL;

if ($c) {
    echo $properties[0]->getValue($a) . PHP_EOL;
}

Expected result:
----------------
I'm not sure what is expected behaviour, but it's strange to have abiliti get property of ArrayObject and have not ability to get value of this property.

Variants:
1. Properties have not be returned by ReflectionObject::getProperties()
------ EXPECTED -----
1
testValue
------ EXPECTED -----


2. Property values should be accessible by ReflectionProperty::getValue()
------ EXPECTED -----
0
------ EXPECTED -----

Actual result:
--------------
1

Notice: Undefined property: A::$test in /in/FbMbQ on line 14


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-05 17:02 UTC] ilya at antipenko dot pp dot ua
Seems caused by https://bugs.php.net/bug.php?id=72174
 [2016-12-05 19:21 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2016-12-05 19:21 UTC] cmb@php.net
Indeed, the notice is caused by commit a1ed4ab3[1]. However, the behavior didn't make sense before that commit, because the property's value was returned as NULL[2]. It seems to me that ::getProperties() should return 0 (as done by HHVM).

[1] <http://git.php.net/?p=php-src.git;a=commit;h=a1ed4ab3>
[2] <https://3v4l.org/UcTHf>
 [2020-02-28 15:15 UTC] nikic@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-02-28 15:15 UTC] nikic@php.net
This has been fixed in PHP 7.4: ArrayObject no longer reports the array contents as properties to reflection.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 15:01:28 2024 UTC