-
Notifications
You must be signed in to change notification settings - Fork 7.8k
/
Copy pathproperty_recreate_protected.phpt
56 lines (49 loc) · 1.25 KB
/
property_recreate_protected.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
--TEST--
Unsetting and recreating protected properties.
--FILE--
<?php
class C {
protected $p = 'test';
function unsetProtected() {
unset($this->p);
}
function setProtected() {
$this->p = 'changed';
}
}
class D extends C {
function setP() {
$this->p = 'changed in D';
}
}
$d = new D;
echo "Unset and recreate a protected property from property's declaring class scope:\n";
$d->unsetProtected();
$d->setProtected();
var_dump($d);
echo "\nUnset and recreate a protected property from subclass:\n";
$d = new D;
$d->unsetProtected();
$d->setP();
var_dump($d);
echo "\nUnset a protected property, and attempt to recreate it outside of scope (expected failure):\n";
$d->unsetProtected();
$d->p = 'this will fail';
var_dump($d);
?>
--EXPECTF--
Unset and recreate a protected property from property's declaring class scope:
object(D)#%d (1) {
["p":protected]=>
string(7) "changed"
}
Unset and recreate a protected property from subclass:
object(D)#%d (1) {
["p":protected]=>
string(12) "changed in D"
}
Unset a protected property, and attempt to recreate it outside of scope (expected failure):
Fatal error: Uncaught Error: Cannot access protected property %s::$p in %s:32
Stack trace:
#0 {main}
thrown in %s on line 32