1--TEST--
2Test ReflectionProperty::setValue() error cases.
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$instanceWithNoProperties = new AnotherClass();
19$propInfo = new ReflectionProperty('TestClass', 'pub2');
20
21echo "\nProtected property:\n";
22try {
23    $propInfo = new ReflectionProperty('TestClass', 'prot');
24    var_dump($propInfo->setValue($instance, "NewValue"));
25}
26catch(Exception $exc) {
27    echo $exc->getMessage();
28}
29
30echo "\n\nInstance without property:\n";
31$propInfo = new ReflectionProperty('TestClass', 'pub2');
32var_dump($propInfo->setValue($instanceWithNoProperties, "NewValue"));
33var_dump($instanceWithNoProperties->pub2);
34?>
35--EXPECT--
36Protected property:
37Cannot access non-public property TestClass::$prot
38
39Instance without property:
40NULL
41string(8) "NewValue"
42