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