xref: /PHP-7.1/ext/reflection/tests/bug45139.phpt (revision 5050450f)
1--TEST--
2Bug #45139 (ReflectionProperty returns incorrect declaring class)
3--FILE--
4<?php
5
6class A {
7	private $foo;
8}
9
10class B extends A {
11	protected $bar;
12	private $baz;
13	private $quux;
14}
15
16class C extends B {
17	public $foo;
18	private $baz;
19	protected $quux;
20}
21
22$rc = new ReflectionClass('C');
23$rp = $rc->getProperty('foo');
24var_dump($rp->getDeclaringClass()->getName()); // c
25
26$rc = new ReflectionClass('A');
27$rp = $rc->getProperty('foo');
28var_dump($rp->getDeclaringClass()->getName()); // A
29
30$rc = new ReflectionClass('B');
31$rp = $rc->getProperty('bar');
32var_dump($rp->getDeclaringClass()->getName()); // B
33
34$rc = new ReflectionClass('C');
35$rp = $rc->getProperty('bar');
36var_dump($rp->getDeclaringClass()->getName()); // B
37
38$rc = new ReflectionClass('C');
39$rp = $rc->getProperty('baz');
40var_dump($rp->getDeclaringClass()->getName()); // C
41
42$rc = new ReflectionClass('B');
43$rp = $rc->getProperty('baz');
44var_dump($rp->getDeclaringClass()->getName()); // B
45
46$rc = new ReflectionClass('C');
47$rp = $rc->getProperty('quux');
48var_dump($rp->getDeclaringClass()->getName()); // C
49
50?>
51--EXPECT--
52string(1) "C"
53string(1) "A"
54string(1) "B"
55string(1) "B"
56string(1) "C"
57string(1) "B"
58string(1) "C"
59