1--TEST--
2Unsetting and recreating private properties.
3--FILE--
4<?php
5class C {
6    private $p = 'test';
7    function unsetPrivate() {
8        unset($this->p);
9    }
10    function setPrivate() {
11        $this->p = 'changed';
12    }
13}
14
15#[AllowDynamicProperties]
16class D extends C {
17    function setP() {
18        $this->p = 'changed in D';
19    }
20}
21
22echo "Unset and recreate a superclass's private property:\n";
23$d = new D;
24$d->unsetPrivate();
25$d->setPrivate();
26var_dump($d);
27
28echo "\nUnset superclass's private property, and recreate it as public in subclass:\n";
29$d = new D;
30$d->unsetPrivate();
31$d->setP();
32var_dump($d);
33
34echo "\nUnset superclass's private property, and recreate it as public at global scope:\n";
35$d = new D;
36$d->unsetPrivate();
37$d->p = 'this will create a public property';
38var_dump($d);
39
40
41echo "\n\nUnset and recreate a private property:\n";
42$c = new C;
43$c->unsetPrivate();
44$c->setPrivate();
45var_dump($c);
46
47echo "\nUnset a private property, and attempt to recreate at global scope (expecting failure):\n";
48$c = new C;
49$c->unsetPrivate();
50$c->p = 'this will fail';
51var_dump($c);
52?>
53===DONE===
54--EXPECTF--
55Unset and recreate a superclass's private property:
56object(D)#%d (1) {
57  ["p":"C":private]=>
58  string(7) "changed"
59}
60
61Unset superclass's private property, and recreate it as public in subclass:
62object(D)#%d (1) {
63  ["p"]=>
64  string(12) "changed in D"
65}
66
67Unset superclass's private property, and recreate it as public at global scope:
68object(D)#%d (1) {
69  ["p"]=>
70  string(34) "this will create a public property"
71}
72
73
74Unset and recreate a private property:
75object(C)#%d (1) {
76  ["p":"C":private]=>
77  string(7) "changed"
78}
79
80Unset a private property, and attempt to recreate at global scope (expecting failure):
81
82Fatal error: Uncaught Error: Cannot access private property C::$p in %s:%d
83Stack trace:
84#0 {main}
85  thrown in %s on line %d
86