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";
32$propInfo = new ReflectionProperty('TestClass', 'prot');
33var_dump($propInfo->getValue($instance));
34
35echo "\n\nInvalid instance:\n";
36$propInfo = new ReflectionProperty('TestClass', 'pub2');
37try {
38    var_dump($propInfo->getValue($invalidInstance));
39} catch (ReflectionException $e) {
40    echo $e->getMessage();
41}
42
43echo "\n\nMissing instance:\n";
44try {
45    var_dump($propInfo->getValue());
46} catch (TypeError $e) {
47    echo $e->getMessage();
48}
49
50?>
51--EXPECT--
52Instance without property:
53
54Static property / too many args:
55ReflectionProperty::getValue() expects at most 1 argument, 2 given
56
57Protected property:
58int(4)
59
60
61Invalid instance:
62Given object is not an instance of the class this property was declared in
63
64Missing instance:
65ReflectionProperty::getValue(): Argument #1 ($object) must be provided for instance properties
66