blob: 264e720c9ec942280d85b5159b0f255ef807233e (
plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
--TEST--
Un-setting instance properties causes magic methods to be called when trying to access them from outside the magic
methods themselves.
--FILE--
<?php
class Test
{
public $publicProperty = 'publicProperty set';
protected $protectedProperty = 'protectedProperty set';
private $privateProperty = 'privateProperty set';
public function __get($name)
{
return '__get "' . $name . '"';
}
public function __set($name, $value)
{
$this->$name = $value;
echo '__set "' . $name . '" to "' . $value . '"';
}
public function __isset($name)
{
echo '__isset "' . $name . '"';
return isset($this->$name);
}
public function getPublicProperty()
{
return $this->publicProperty;
}
public function setPublicProperty($publicProperty)
{
$this->publicProperty = $publicProperty;
}
public function unsetProtectedProperty()
{
unset($this->protectedProperty);
}
public function getProtectedProperty()
{
return $this->protectedProperty;
}
public function setProtectedProperty($protectedProperty)
{
$this->protectedProperty = $protectedProperty;
}
public function unsetPrivateProperty()
{
unset($this->privateProperty);
}
public function getPrivateProperty()
{
return $this->privateProperty;
}
public function setPrivateProperty($privateProperty)
{
$this->privateProperty = $privateProperty;
}
}
// verifying public property
$o = new Test;
echo $o->publicProperty;
echo "\n";
var_export(isset($o->publicProperty));
echo "\n";
unset($o->publicProperty);
isset($o->publicProperty);
echo "\n";
echo $o->publicProperty;
echo "\n";
echo $o->getPublicProperty();
echo "\n";
echo $o->setPublicProperty('new publicProperty value via setter');
echo "\n";
echo $o->publicProperty;
echo "\n";
unset($o->publicProperty);
$o->publicProperty = 'new publicProperty value via public access';
echo "\n";
var_export(isset($o->publicProperty));
echo "\n";
echo $o->publicProperty;
echo "\n\n";
// verifying protected property
echo $o->getProtectedProperty();
echo "\n";
$o->unsetProtectedProperty();
var_export(isset($o->protectedProperty));
echo "\n";
echo $o->getProtectedProperty();
echo "\n";
echo $o->setProtectedProperty('new protectedProperty value via setter');
echo "\n";
var_export(isset($o->protectedProperty));
echo "\n";
echo $o->getProtectedProperty();
echo "\n\n";
// verifying private property
echo $o->getPrivateProperty();
echo "\n";
$o->unsetPrivateProperty();
var_export(isset($o->privateProperty));
echo "\n";
echo $o->getPrivateProperty();
echo "\n";
echo $o->setPrivateProperty('new privateProperty value via setter');
echo "\n";
var_export(isset($o->privateProperty));
echo "\n";
echo $o->getPrivateProperty();
echo "\n\n";
?>
--EXPECTF--
publicProperty set
true
__isset "publicProperty"
__get "publicProperty"
__get "publicProperty"
__set "publicProperty" to "new publicProperty value via setter"
new publicProperty value via setter
__set "publicProperty" to "new publicProperty value via public access"
true
new publicProperty value via public access
protectedProperty set
__isset "protectedProperty"false
__get "protectedProperty"
__set "protectedProperty" to "new protectedProperty value via setter"
__isset "protectedProperty"true
new protectedProperty value via setter
privateProperty set
__isset "privateProperty"false
__get "privateProperty"
__set "privateProperty" to "new privateProperty value via setter"
__isset "privateProperty"true
new privateProperty value via setter
|