1--TEST--
2Test usage of ReflectionProperty methods __toString(), export(), getName(), isPublic(), isPrivate(), isProtected(), isStatic(), getValue() and setValue().
3--FILE--
4<?php
5
6function reflectProperty($class, $property) {
7    $propInfo = new ReflectionProperty($class, $property);
8    echo "**********************************\n";
9    echo "Reflecting on property $class::$property\n\n";
10    echo "__toString():\n";
11    var_dump($propInfo->__toString());
12    echo "export():\n";
13    var_dump(ReflectionProperty::export($class, $property, true));
14    echo "export():\n";
15    var_dump(ReflectionProperty::export($class, $property, false));
16    echo "getName():\n";
17    var_dump($propInfo->getName());
18    echo "isPublic():\n";
19    var_dump($propInfo->isPublic());
20    echo "isPrivate():\n";
21    var_dump($propInfo->isPrivate());
22    echo "isProtected():\n";
23    var_dump($propInfo->isProtected());
24    echo "isStatic():\n";
25    var_dump($propInfo->isStatic());
26    $instance = new $class();
27    if ($propInfo->isPublic()) {
28        echo "getValue():\n";
29        var_dump($propInfo->getValue($instance));
30        $propInfo->setValue($instance, "NewValue");
31        echo "getValue() after a setValue():\n";
32        var_dump($propInfo->getValue($instance));
33    }
34    echo "\n**********************************\n";
35}
36
37class TestClass {
38    public $pub;
39    static public $stat = "static property";
40    protected $prot = 4;
41    private $priv = "keepOut";
42}
43
44reflectProperty("TestClass", "pub");
45reflectProperty("TestClass", "stat");
46reflectProperty("TestClass", "prot");
47reflectProperty("TestClass", "priv");
48
49?>
50--EXPECT--
51**********************************
52Reflecting on property TestClass::pub
53
54__toString():
55string(35) "Property [ <default> public $pub ]
56"
57export():
58string(35) "Property [ <default> public $pub ]
59"
60export():
61Property [ <default> public $pub ]
62
63NULL
64getName():
65string(3) "pub"
66isPublic():
67bool(true)
68isPrivate():
69bool(false)
70isProtected():
71bool(false)
72isStatic():
73bool(false)
74getValue():
75NULL
76getValue() after a setValue():
77string(8) "NewValue"
78
79**********************************
80**********************************
81Reflecting on property TestClass::stat
82
83__toString():
84string(33) "Property [ public static $stat ]
85"
86export():
87string(33) "Property [ public static $stat ]
88"
89export():
90Property [ public static $stat ]
91
92NULL
93getName():
94string(4) "stat"
95isPublic():
96bool(true)
97isPrivate():
98bool(false)
99isProtected():
100bool(false)
101isStatic():
102bool(true)
103getValue():
104string(15) "static property"
105getValue() after a setValue():
106string(8) "NewValue"
107
108**********************************
109**********************************
110Reflecting on property TestClass::prot
111
112__toString():
113string(39) "Property [ <default> protected $prot ]
114"
115export():
116string(39) "Property [ <default> protected $prot ]
117"
118export():
119Property [ <default> protected $prot ]
120
121NULL
122getName():
123string(4) "prot"
124isPublic():
125bool(false)
126isPrivate():
127bool(false)
128isProtected():
129bool(true)
130isStatic():
131bool(false)
132
133**********************************
134**********************************
135Reflecting on property TestClass::priv
136
137__toString():
138string(37) "Property [ <default> private $priv ]
139"
140export():
141string(37) "Property [ <default> private $priv ]
142"
143export():
144Property [ <default> private $priv ]
145
146NULL
147getName():
148string(4) "priv"
149isPublic():
150bool(false)
151isPrivate():
152bool(true)
153isProtected():
154bool(false)
155isStatic():
156bool(false)
157
158**********************************
159
160
161