php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75231 ReflectionProperty#getValue() incorrectly works with inherited classes.
Submitted: 2017-09-20 08:22 UTC Modified: 2017-09-20 11:51 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: t at elless dot me Assigned: krakjoe (profile)
Status: Assigned Package: Reflection related
PHP Version: 7.1.9 OS: Linux (CentOS)
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-09-20 08:22 UTC] t at elless dot me
Description:
------------
Relates to https://bugs.php.net/bug.php?id=72209

`ReflectionProperty#getValue($object)` probably incorrectly checks the type of $object. 

`ReflectionProperty#invoke($object)` correctly detect inheritance.

Anyway fix 72209 bug has BC which were not specified in the changes 7.0 => 7.1.
And error message kinda incorrect. "Given object is not an instance of the class this property was declared in" bug given object is exactly an instance of the class this property was declared in.

Test script:
---------------
https://gist.github.com/telless/fe942e202b408b1b614faf638d7aea30

Expected result:
----------------
method
prop

Actual result:
--------------
method
PHP Fatal error:  Uncaught ReflectionException: Given object is not an instance of the class this property was declared in in php71reflection.php:23


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-09-20 11:51 UTC] cmb@php.net
-Assigned To: +Assigned To: krakjoe
 [2017-09-20 11:51 UTC] cmb@php.net
It seems to me that the current implementation checks whether the given object
is an instance of the ReflectionProperty object's class property[1]. So indeed,
either the exception message is wrong, or the implementation. Not sure which.
Joe?

[1] <https://github.com/php/php-src/blob/php-7.1.9/ext/reflection/php_reflection.c#L5648>
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC