Skip to content

Commit c97b8bb

Browse files
committed
Fixed bug #75231
The behavior is now consistent with ReflectionMethod.
1 parent 787593b commit c97b8bb

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ PHP NEWS
3636
- Reflection:
3737
. Fixed bug #76536 (PHP crashes with core dump when throwing exception in
3838
error handler). (Laruence)
39+
. Fixed bug #75231 (ReflectionProperty#getValue() incorrectly works with
40+
inherited classes). (Nikita)
3941

4042
- Standard:
4143
. Fixed bug #76505 (array_merge_recursive() is duplicating sub-array keys).

ext/reflection/php_reflection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5645,7 +5645,7 @@ ZEND_METHOD(reflection_property, getValue)
56455645
return;
56465646
}
56475647

5648-
if (!instanceof_function(Z_OBJCE_P(object), ref->ce)) {
5648+
if (!instanceof_function(Z_OBJCE_P(object), ref->prop.ce)) {
56495649
_DO_THROW("Given object is not an instance of the class this property was declared in");
56505650
/* Returns from this function */
56515651
}

ext/reflection/tests/bug75231.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Bug #75231: ReflectionProperty#getValue() incorrectly works with inherited classes
3+
--FILE--
4+
<?php
5+
class A
6+
{
7+
public $prop;
8+
public function __construct()
9+
{
10+
$this->prop = 'prop';
11+
}
12+
public function method()
13+
{
14+
return 'method';
15+
}
16+
}
17+
class B extends A
18+
{
19+
}
20+
print_r((new ReflectionMethod(B::class, 'method'))->invoke(new A()).PHP_EOL);
21+
print_r((new ReflectionProperty(B::class, 'prop'))->getValue(new A()).PHP_EOL);
22+
?>
23+
--EXPECT--
24+
method
25+
prop

0 commit comments

Comments
 (0)