1--TEST--
2Test ReflectionProperty::getValue() errors.
3--FILE--
4<?php
5
6class TestClass {
7    public $pub;
8    public $pub2 = 5;
9    static public $stat = "static property";
10    protected $prot = 4;
11    private $priv = "keepOut";
12}
13
14class AnotherClass {
15}
16
17$instance = new TestClass();
18$invalidInstance = new AnotherClass();
19$propInfo = new ReflectionProperty('TestClass', 'pub2');
20
21echo "\nInstance without property:\n";
22$propInfo = new ReflectionProperty('TestClass', 'stat');
23
24echo "\nStatic property / too many args:\n";
25try {
26    var_dump($propInfo->getValue($instance, true));
27} catch (TypeError $e) {
28    echo $e->getMessage(), "\n";
29}
30
31echo "\nProtected property:\n";
32try {
33    $propInfo = new ReflectionProperty('TestClass', 'prot');
34    var_dump($propInfo->getValue($instance));
35}
36catch(Exception $exc) {
37    echo $exc->getMessage();
38}
39
40echo "\n\nInvalid instance:\n";
41$propInfo = new ReflectionProperty('TestClass', 'pub2');
42try {
43    var_dump($propInfo->getValue($invalidInstance));
44} catch (ReflectionException $e) {
45    echo $e->getMessage();
46}
47
48echo "\n\nMissing instance:\n";
49try {
50    var_dump($propInfo->getValue());
51} catch (TypeError $e) {
52    echo $e->getMessage();
53}
54
55?>
56--EXPECT--
57Instance without property:
58
59Static property / too many args:
60ReflectionProperty::getValue() expects at most 1 argument, 2 given
61
62Protected property:
63Cannot access non-public property TestClass::$prot
64
65Invalid instance:
66Given object is not an instance of the class this property was declared in
67
68Missing instance:
69ReflectionProperty::getValue(): Argument #1 ($object) must be provided for instance properties
70