1--TEST--
2Property hook reflection
3--FILE--
4<?php
5
6class Test {
7    public $prop1;
8    public $prop2 { get {} set {} }
9    public $prop3 {
10        get { echo "get\n"; }
11        set { echo "set($value)\n"; }
12    }
13    public $prop5 { get { echo "get\n"; } }
14    public $prop6 { set { echo "set($value)\n"; } }
15}
16abstract class Test2 {
17    abstract public $prop4 { get; set; }
18}
19
20function dumpFlags(ReflectionProperty $rp) {
21    $modifiers = $rp->getModifiers();
22    echo "Abstract: ";
23    echo $rp->isAbstract() ? "true" : "false";
24    echo " ";
25    echo $modifiers & ReflectionProperty::IS_ABSTRACT ? "true" : "false";
26    echo "\n";
27}
28
29$test = new Test;
30
31$rp1 = new ReflectionProperty(Test::class, 'prop1');
32var_dump($rp1->hasHook(PropertyHookType::Get));
33var_dump($rp1->getHook(PropertyHookType::Get));
34var_dump($rp1->hasHook(PropertyHookType::Set));
35var_dump($rp1->getHook(PropertyHookType::Set));
36dumpFlags($rp1);
37echo "\n";
38
39$rp2 = new ReflectionProperty(Test::class, 'prop2');
40var_dump($rp2->hasHook(PropertyHookType::Get));
41var_dump($g = $rp2->getHook(PropertyHookType::Get));
42var_dump($rp2->hasHook(PropertyHookType::Set));
43var_dump($s = $rp2->getHook(PropertyHookType::Set));
44var_dump($g->invoke($test));
45try {
46    $s->invoke($test, 42);
47} catch (ReflectionException $e) {
48    echo $e->getMessage(), "\n";
49}
50$s->setAccessible(true);
51$s->invoke($test, 42);
52var_dump($test->prop2);
53dumpFlags($rp2);
54echo "\n";
55
56$rp3 = new ReflectionProperty(Test::class, 'prop3');
57var_dump($rp3->hasHook(PropertyHookType::Get));
58var_dump($g = $rp3->getHook(PropertyHookType::Get));
59var_dump($rp3->hasHook(PropertyHookType::Set));
60var_dump($s = $rp3->getHook(PropertyHookType::Set));
61$g->invoke($test);
62$s->invoke($test, 42);
63dumpFlags($rp3);
64echo "\n";
65
66$rp4 = new ReflectionProperty(Test2::class, 'prop4');
67dumpFlags($rp4);
68echo "\n";
69
70$rp5 = new ReflectionProperty(Test::class, 'prop5');
71var_dump($rp5->hasHook(PropertyHookType::Get));
72var_dump($rp5->hasHook(PropertyHookType::Set));
73echo "\n";
74
75$rp6 = new ReflectionProperty(Test::class, 'prop6');
76var_dump($rp6->hasHook(PropertyHookType::Get));
77var_dump($rp6->hasHook(PropertyHookType::Set));
78echo "\n";
79
80?>
81--EXPECT--
82bool(false)
83NULL
84bool(false)
85NULL
86Abstract: false false
87
88bool(true)
89object(ReflectionMethod)#6 (2) {
90  ["name"]=>
91  string(11) "$prop2::get"
92  ["class"]=>
93  string(4) "Test"
94}
95bool(true)
96object(ReflectionMethod)#7 (2) {
97  ["name"]=>
98  string(11) "$prop2::set"
99  ["class"]=>
100  string(4) "Test"
101}
102NULL
103NULL
104Abstract: false false
105
106bool(true)
107object(ReflectionMethod)#9 (2) {
108  ["name"]=>
109  string(11) "$prop3::get"
110  ["class"]=>
111  string(4) "Test"
112}
113bool(true)
114object(ReflectionMethod)#6 (2) {
115  ["name"]=>
116  string(11) "$prop3::set"
117  ["class"]=>
118  string(4) "Test"
119}
120get
121set(42)
122Abstract: false false
123
124Abstract: true true
125
126bool(true)
127bool(false)
128
129bool(false)
130bool(true)
131