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 "Too few args:\n";
22var_dump($propInfo->getValue());
23
24echo "\nToo many args:\n";
25var_dump($propInfo->getValue($instance, true));
26
27echo "\nWrong type of arg:\n";
28var_dump($propInfo->getValue(true));
29
30echo "\nInstance without property:\n";
31$propInfo = new ReflectionProperty('TestClass', 'stat');
32
33echo "\nStatic property / too many args:\n";
34var_dump($propInfo->getValue($instance, true));
35
36echo "\nStatic property / wrong type of arg:\n";
37var_dump($propInfo->getValue(true));
38
39echo "\nProtected property:\n";
40try {
41    $propInfo = new ReflectionProperty('TestClass', 'prot');
42    var_dump($propInfo->getValue($instance));
43}
44catch(Exception $exc) {
45    echo $exc->getMessage();
46}
47
48echo "\n\nInvalid instance:\n";
49$propInfo = new ReflectionProperty('TestClass', 'pub2');
50var_dump($propInfo->getValue($invalidInstance));
51
52?>
53--EXPECTF--
54Too few args:
55
56Warning: ReflectionProperty::getValue() expects exactly 1 parameter, 0 given in %s on line %d
57NULL
58
59Too many args:
60
61Warning: ReflectionProperty::getValue() expects exactly 1 parameter, 2 given in %s on line %d
62NULL
63
64Wrong type of arg:
65
66Warning: ReflectionProperty::getValue() expects parameter 1 to be object, bool given in %s on line %d
67NULL
68
69Instance without property:
70
71Static property / too many args:
72string(15) "static property"
73
74Static property / wrong type of arg:
75string(15) "static property"
76
77Protected property:
78Cannot access non-public member TestClass::$prot
79
80Invalid instance:
81
82Fatal error: Uncaught ReflectionException: Given object is not an instance of the class this property was declared in in %s:47
83Stack trace:
84#0 %s(47): ReflectionProperty->getValue(Object(AnotherClass))
85#1 {main}
86  thrown in %s on line 47
87