Skip to content

Commit 5c5dcf5

Browse files
committed
MFH: Fixed bug #48336 (ReflectionProperty::getDeclaringClass() does not
work with redeclared property) (patch by Markus dot Lidel at shadowconnect dot com)
1 parent 9aca3c0 commit 5c5dcf5

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

ext/reflection/php_reflection.c

+4
Original file line numberDiff line numberDiff line change
@@ -4603,6 +4603,10 @@ ZEND_METHOD(reflection_property, getDeclaringClass)
46034603
break;
46044604
}
46054605
ce = tmp_ce;
4606+
if (tmp_ce == tmp_info->ce) {
4607+
/* declared in this class, done */
4608+
break;
4609+
}
46064610
tmp_ce = tmp_ce->parent;
46074611
}
46084612

ext/reflection/tests/bug48336.phpt

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--TEST--
2+
Bug #48286 (ReflectionProperty::getDeclaringClass() does not work with redeclared properties)
3+
--FILE--
4+
<?php
5+
class A {
6+
}
7+
8+
class B extends A {
9+
static protected $prop;
10+
}
11+
12+
class C extends B {
13+
static protected $prop;
14+
}
15+
16+
class D extends C {
17+
}
18+
19+
class E extends D {
20+
}
21+
22+
class F extends E {
23+
static protected $prop;
24+
}
25+
26+
$class = 'A';
27+
for($class = 'A'; $class <= 'F'; $class ++) {
28+
print($class.' => ');
29+
try {
30+
$rp = new ReflectionProperty($class, 'prop');
31+
print($rp->getDeclaringClass()->getName());
32+
} catch(Exception $e) {
33+
print('N/A');
34+
}
35+
print("\n");
36+
}
37+
?>
38+
--EXPECT--
39+
A => N/A
40+
B => B
41+
C => C
42+
D => C
43+
E => C
44+
F => F

0 commit comments

Comments
 (0)