xref: /PHP-8.0/ext/reflection/tests/bug46064.phpt (revision f8d79582)
1--TEST--
2Bug #46064 (Exception when creating ReflectionProperty object on dynamicly created property)
3--FILE--
4<?php
5
6class x {
7    public $zzz = 2;
8}
9
10$o = new x;
11$o->z = 1000;
12$o->zzz = 3;
13
14var_dump($h = new reflectionproperty($o, 'z'));
15var_dump($h->isDefault());
16var_dump($h->isPublic());
17var_dump($h->isStatic());
18var_dump($h->getName());
19var_dump(Reflection::getModifierNames($h->getModifiers()));
20var_dump($h->getValue($o));
21
22print "---------------------------\n";
23try {
24    var_dump(new reflectionproperty($o, 'zz'));
25} catch (Exception $e) {
26    var_dump($e->getMessage());
27}
28
29var_dump(new reflectionproperty($o, 'zzz'));
30
31class test {
32    protected $a = 1;
33}
34
35class bar extends test {
36    public function __construct() {
37        $this->foobar = 2;
38        $this->a = 200;
39
40        $p = new reflectionproperty($this, 'foobar');
41        var_dump($p->getValue($this), $p->isDefault(), $p->isPublic());
42    }
43}
44
45new bar;
46
47?>
48--EXPECTF--
49object(ReflectionProperty)#%d (2) {
50  ["name"]=>
51  string(1) "z"
52  ["class"]=>
53  string(1) "x"
54}
55bool(false)
56bool(true)
57bool(false)
58string(1) "z"
59array(1) {
60  [0]=>
61  string(6) "public"
62}
63int(1000)
64---------------------------
65string(30) "Property x::$zz does not exist"
66object(ReflectionProperty)#%d (2) {
67  ["name"]=>
68  string(3) "zzz"
69  ["class"]=>
70  string(1) "x"
71}
72int(2)
73bool(false)
74bool(true)
75