global statement removal: hphp/test [7/x]
[hiphop-php.git] / hphp / test / quick / properties3.php
blob19a73c8a0b6281c63e946553e354c99bd3125075
1 <?hh
3 // class with __get and __set
4 class A {
5 private $x;
6 public $y;
8 function unsetall() {
9 unset($this->x);
10 unset($this->y);
13 function __get($n) {
14 echo "A::__get $n\n";
15 return $n;
18 function __set($n, $v) {
19 echo "A::__set $n, $v\n";
22 function setprop() {
23 $this->x = 1;
24 $this->y = 2;
25 var_dump($this);
28 function setopprop() {
29 $this->x += 1;
30 $this->y += 2;
31 var_dump($this);
34 function incdecprop() {
35 $this->x++;
36 $this->y++;
37 var_dump($this);
41 // class with __get but not __set
42 class B {
43 private $x;
44 public $y;
46 function unsetall() {
47 unset($this->x);
48 unset($this->y);
51 function __get($n) {
52 echo "B::__get $n\n";
53 return $n;
56 function setprop() {
57 $this->x = 1;
58 $this->y = 2;
59 var_dump($this);
62 function setopprop() {
63 $this->x += 1;
64 $this->y += 2;
65 var_dump($this);
68 function incdecprop() {
69 $this->x++;
70 $this->y++;
71 var_dump($this);
75 // class with __set but not __get
76 class C {
77 private $x;
78 public $y;
80 function unsetall() {
81 unset($this->x);
82 unset($this->y);
85 function __set($n, $v) {
86 echo "C::__set $n, $v\n";
89 function setprop() {
90 $this->x = 1;
91 $this->y = 2;
92 var_dump($this);
95 function setopprop() {
96 $this->x += 1;
97 $this->y += 2;
98 var_dump($this);
101 function incdecprop() {
102 $this->x++;
103 $this->y++;
104 var_dump($this);
108 // class without __get or __set
109 class D {
110 private $x;
111 public $y;
113 function unsetall() {
114 unset($this->x);
115 unset($this->y);
118 function setprop() {
119 $this->x = 1;
120 $this->y = 2;
121 var_dump($this);
124 function setopprop() {
125 $this->x += 1;
126 $this->y += 2;
127 var_dump($this);
130 function incdecprop() {
131 $this->x++;
132 $this->y++;
133 var_dump($this);
137 function propd(&$x) {
138 var_dump($x);
141 $a = new A;
142 // unset all properties
143 $a->unsetall();
144 // Prop for visible, accessible property: use __get
145 var_dump($a->y);
146 // Prop for visible, inaccessible property: use __get
147 var_dump($a->x);
148 // PropD for visible, accessible property: use __get
149 propd(&$a->y);
150 // PropD for visible, inaccessible property: use __get
151 propd(&$a->x);
152 // PropU for visible, accessible property
153 unset($a->y);
155 // SetProp for visible, accessible properties: use __set
156 $a->setprop();
158 // SetOpProp: use __set and __get
159 $a->unsetall();
160 $a->setopprop();
161 // IncDecProp: use __set and __get
162 $a->unsetall();
163 $a->incdecprop();
165 $b = new B;
166 // unset all properties
167 $b->unsetall();
168 // SetOpProp: use __get
169 $b->setopprop();
170 // IncDecProp: use __get
171 $b->unsetall();
172 $b->incdecprop();
174 $c = new C;
175 // unset all properties
176 $c->unsetall();
177 // SetOpProp
178 $c->setopprop();
179 // IncDecProp
180 $c->unsetall();
181 $c->incdecprop();
183 $d = new D;
184 // unset all properties
185 $d->unsetall();
186 // Prop for visible, accessible property
187 var_dump($d->y);
188 // PropD for visible, accessible property
189 propd(&$d->y);
190 // PropU for visible, accessible property
191 unset($d->y);
192 // SetProp for visible, accessible properties
193 $d->setprop();
194 // SetOpProp
195 $d->unsetall();
196 $d->setopprop();
197 // IncDecProp
198 $d->unsetall();
199 $d->incdecprop();