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:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: t at elless dot me Assigned: krakjoe (profile)
Status: Closed Package: Reflection related
PHP Version: 7.1.9 OS: Linux (CentOS)
Private report: No CVE-ID: None
 [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

Pull Requests

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>
 [2018-07-02 16:58 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=c97b8bbf8252c3a493a44bcb91fb137952f03710
Log: Fixed bug #75231
 [2018-07-02 16:58 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC