xref: /PHP-5.4/ext/spl/tests/array_017.phpt (revision 610c7fbe)
1--TEST--
2SPL: ArrayObject::exchangeArray($this)
3--FILE--
4<?php
5
6class ArrayIteratorEx extends ArrayIterator
7{
8	public    $pub2 = 1;
9	protected $pro2 = 2;
10	private   $pri2 = 3;
11
12	function __construct($ar, $flags = 0)
13	{
14		echo __METHOD__ . "()\n";
15		parent::__construct($ar, $flags);
16		$this->imp2 = 4;
17	}
18
19	function dump()
20	{
21		echo __METHOD__ . "()\n";
22		var_dump(array('Flags'=>$this->getFlags()
23		              ,'OVars'=>get_object_vars($this)
24		              ,'$this'=>$this));
25	}
26
27	function setFlags($flags)
28	{
29		echo __METHOD__ . "($flags)\n";
30		ArrayIterator::setFlags($flags);
31	}
32}
33
34class ArrayObjectEx extends ArrayObject
35{
36	public    $pub1 = 1;
37	protected $pro1 = 2;
38	private   $pri1 = 3;
39
40	function __construct($ar = array(), $flags = 0)
41	{
42		echo __METHOD__ . "()\n";
43		parent::__construct($ar, $flags);
44		$this->imp1 = 4;
45	}
46
47	function exchange()
48	{
49		echo __METHOD__ . "()\n";
50		$this->exchangeArray($this);
51	}
52
53	function dump()
54	{
55		echo __METHOD__ . "()\n";
56		var_dump(array('Flags'=>$this->getFlags()
57		              ,'OVars'=>get_object_vars($this)
58		              ,'$this'=>$this));
59	}
60
61	function show()
62	{
63		echo __METHOD__ . "()\n";
64		foreach($this as $n => $v)
65		{
66			var_dump(array($n => $v));
67		}
68	}
69
70	function setFlags($flags)
71	{
72		echo __METHOD__ . "($flags)\n";
73		ArrayObject::setFlags($flags);
74	}
75
76	function getIterator()
77	{
78		echo __METHOD__ . "()\n";
79		$it = new ArrayIteratorEx($this, $this->getFlags());
80		$it->dyn2 = 5;
81		$it->dump();
82		return $it;
83	}
84}
85
86function check($obj, $flags)
87{
88	echo "===CHECK===\n";
89
90	$obj->setFlags($flags);
91	$obj->dump();
92	$obj->show();
93
94	echo "===FOREACH===\n";
95
96	$it = $obj->getIterator();
97	foreach($it as $n => $v)
98	{
99		var_dump(array($n => $v));
100	}
101
102	echo "===PROPERTY===\n";
103
104	var_dump($obj->pub1);
105	var_dump(isset($obj->a));
106	$obj->setFlags($flags | 2);
107	var_dump($obj->pub1);
108	var_dump(isset($obj->a));
109
110	var_dump($it->pub2);
111	var_dump(isset($it->pub1));
112	$it->setFlags($flags | 2);
113	var_dump($it->pub2);
114	var_dump(isset($it->pub1));
115}
116
117$obj = new ArrayObjectEx(array(0=>1,'a'=>25, 'pub1'=>42), 0);
118$obj->dyn1 = 5;
119
120check($obj, 0);
121check($obj, 1);
122
123echo "#####EXCHANGE#####\n";
124
125$obj->exchange();
126
127check($obj, 0);
128check($obj, 1);
129
130?>
131===DONE===
132<?php exit(0); ?>
133--EXPECTF--
134ArrayObjectEx::__construct()
135===CHECK===
136ArrayObjectEx::setFlags(0)
137ArrayObjectEx::dump()
138array(3) {
139  ["Flags"]=>
140  int(0)
141  ["OVars"]=>
142  array(2) {
143    ["a"]=>
144    int(25)
145    ["pub1"]=>
146    int(42)
147  }
148  ["$this"]=>
149  object(ArrayObjectEx)#%d (6) {
150    ["pub1"]=>
151    int(1)
152    ["pro1":protected]=>
153    int(2)
154    ["pri1":"ArrayObjectEx":private]=>
155    int(3)
156    ["imp1"]=>
157    int(4)
158    ["dyn1"]=>
159    int(5)
160    ["storage":"ArrayObject":private]=>
161    array(3) {
162      [0]=>
163      int(1)
164      ["a"]=>
165      int(25)
166      ["pub1"]=>
167      int(42)
168    }
169  }
170}
171ArrayObjectEx::show()
172ArrayObjectEx::getIterator()
173ArrayIteratorEx::__construct()
174ArrayIteratorEx::dump()
175array(3) {
176  ["Flags"]=>
177  int(0)
178  ["OVars"]=>
179  array(2) {
180    ["a"]=>
181    int(25)
182    ["pub1"]=>
183    int(42)
184  }
185  ["$this"]=>
186  object(ArrayIteratorEx)#%d (6) {
187    ["pub2"]=>
188    int(1)
189    ["pro2":protected]=>
190    int(2)
191    ["pri2":"ArrayIteratorEx":private]=>
192    int(3)
193    ["imp2"]=>
194    int(4)
195    ["dyn2"]=>
196    int(5)
197    ["storage":"ArrayIterator":private]=>
198    object(ArrayObjectEx)#%d (6) {
199      ["pub1"]=>
200      int(1)
201      ["pro1":protected]=>
202      int(2)
203      ["pri1":"ArrayObjectEx":private]=>
204      int(3)
205      ["imp1"]=>
206      int(4)
207      ["dyn1"]=>
208      int(5)
209      ["storage":"ArrayObject":private]=>
210      array(3) {
211        [0]=>
212        int(1)
213        ["a"]=>
214        int(25)
215        ["pub1"]=>
216        int(42)
217      }
218    }
219  }
220}
221array(1) {
222  [0]=>
223  int(1)
224}
225array(1) {
226  ["a"]=>
227  int(25)
228}
229array(1) {
230  ["pub1"]=>
231  int(42)
232}
233===FOREACH===
234ArrayObjectEx::getIterator()
235ArrayIteratorEx::__construct()
236ArrayIteratorEx::dump()
237array(3) {
238  ["Flags"]=>
239  int(0)
240  ["OVars"]=>
241  array(2) {
242    ["a"]=>
243    int(25)
244    ["pub1"]=>
245    int(42)
246  }
247  ["$this"]=>
248  object(ArrayIteratorEx)#%d (6) {
249    ["pub2"]=>
250    int(1)
251    ["pro2":protected]=>
252    int(2)
253    ["pri2":"ArrayIteratorEx":private]=>
254    int(3)
255    ["imp2"]=>
256    int(4)
257    ["dyn2"]=>
258    int(5)
259    ["storage":"ArrayIterator":private]=>
260    object(ArrayObjectEx)#%d (6) {
261      ["pub1"]=>
262      int(1)
263      ["pro1":protected]=>
264      int(2)
265      ["pri1":"ArrayObjectEx":private]=>
266      int(3)
267      ["imp1"]=>
268      int(4)
269      ["dyn1"]=>
270      int(5)
271      ["storage":"ArrayObject":private]=>
272      array(3) {
273        [0]=>
274        int(1)
275        ["a"]=>
276        int(25)
277        ["pub1"]=>
278        int(42)
279      }
280    }
281  }
282}
283array(1) {
284  [0]=>
285  int(1)
286}
287array(1) {
288  ["a"]=>
289  int(25)
290}
291array(1) {
292  ["pub1"]=>
293  int(42)
294}
295===PROPERTY===
296int(1)
297bool(false)
298ArrayObjectEx::setFlags(2)
299int(1)
300bool(true)
301int(1)
302bool(false)
303ArrayIteratorEx::setFlags(2)
304int(1)
305bool(true)
306===CHECK===
307ArrayObjectEx::setFlags(1)
308ArrayObjectEx::dump()
309array(3) {
310  ["Flags"]=>
311  int(1)
312  ["OVars"]=>
313  array(5) {
314    ["pub1"]=>
315    int(1)
316    ["pro1"]=>
317    int(2)
318    ["pri1"]=>
319    int(3)
320    ["imp1"]=>
321    int(4)
322    ["dyn1"]=>
323    int(5)
324  }
325  ["$this"]=>
326  object(ArrayObjectEx)#%d (6) {
327    ["pub1"]=>
328    int(1)
329    ["pro1":protected]=>
330    int(2)
331    ["pri1":"ArrayObjectEx":private]=>
332    int(3)
333    ["imp1"]=>
334    int(4)
335    ["dyn1"]=>
336    int(5)
337    ["storage":"ArrayObject":private]=>
338    array(3) {
339      [0]=>
340      int(1)
341      ["a"]=>
342      int(25)
343      ["pub1"]=>
344      int(42)
345    }
346  }
347}
348ArrayObjectEx::show()
349ArrayObjectEx::getIterator()
350ArrayIteratorEx::__construct()
351ArrayIteratorEx::dump()
352array(3) {
353  ["Flags"]=>
354  int(1)
355  ["OVars"]=>
356  array(5) {
357    ["pub2"]=>
358    int(1)
359    ["pro2"]=>
360    int(2)
361    ["pri2"]=>
362    int(3)
363    ["imp2"]=>
364    int(4)
365    ["dyn2"]=>
366    int(5)
367  }
368  ["$this"]=>
369  object(ArrayIteratorEx)#%d (6) {
370    ["pub2"]=>
371    int(1)
372    ["pro2":protected]=>
373    int(2)
374    ["pri2":"ArrayIteratorEx":private]=>
375    int(3)
376    ["imp2"]=>
377    int(4)
378    ["dyn2"]=>
379    int(5)
380    ["storage":"ArrayIterator":private]=>
381    object(ArrayObjectEx)#%d (6) {
382      ["pub1"]=>
383      int(1)
384      ["pro1":protected]=>
385      int(2)
386      ["pri1":"ArrayObjectEx":private]=>
387      int(3)
388      ["imp1"]=>
389      int(4)
390      ["dyn1"]=>
391      int(5)
392      ["storage":"ArrayObject":private]=>
393      array(3) {
394        [0]=>
395        int(1)
396        ["a"]=>
397        int(25)
398        ["pub1"]=>
399        int(42)
400      }
401    }
402  }
403}
404array(1) {
405  [0]=>
406  int(1)
407}
408array(1) {
409  ["a"]=>
410  int(25)
411}
412array(1) {
413  ["pub1"]=>
414  int(42)
415}
416===FOREACH===
417ArrayObjectEx::getIterator()
418ArrayIteratorEx::__construct()
419ArrayIteratorEx::dump()
420array(3) {
421  ["Flags"]=>
422  int(1)
423  ["OVars"]=>
424  array(5) {
425    ["pub2"]=>
426    int(1)
427    ["pro2"]=>
428    int(2)
429    ["pri2"]=>
430    int(3)
431    ["imp2"]=>
432    int(4)
433    ["dyn2"]=>
434    int(5)
435  }
436  ["$this"]=>
437  object(ArrayIteratorEx)#%d (6) {
438    ["pub2"]=>
439    int(1)
440    ["pro2":protected]=>
441    int(2)
442    ["pri2":"ArrayIteratorEx":private]=>
443    int(3)
444    ["imp2"]=>
445    int(4)
446    ["dyn2"]=>
447    int(5)
448    ["storage":"ArrayIterator":private]=>
449    object(ArrayObjectEx)#%d (6) {
450      ["pub1"]=>
451      int(1)
452      ["pro1":protected]=>
453      int(2)
454      ["pri1":"ArrayObjectEx":private]=>
455      int(3)
456      ["imp1"]=>
457      int(4)
458      ["dyn1"]=>
459      int(5)
460      ["storage":"ArrayObject":private]=>
461      array(3) {
462        [0]=>
463        int(1)
464        ["a"]=>
465        int(25)
466        ["pub1"]=>
467        int(42)
468      }
469    }
470  }
471}
472array(1) {
473  [0]=>
474  int(1)
475}
476array(1) {
477  ["a"]=>
478  int(25)
479}
480array(1) {
481  ["pub1"]=>
482  int(42)
483}
484===PROPERTY===
485int(1)
486bool(false)
487ArrayObjectEx::setFlags(3)
488int(1)
489bool(true)
490int(1)
491bool(false)
492ArrayIteratorEx::setFlags(3)
493int(1)
494bool(true)
495#####EXCHANGE#####
496ArrayObjectEx::exchange()
497===CHECK===
498ArrayObjectEx::setFlags(0)
499ArrayObjectEx::dump()
500array(3) {
501  ["Flags"]=>
502  int(0)
503  ["OVars"]=>
504  array(5) {
505    ["pub1"]=>
506    int(1)
507    ["pro1"]=>
508    int(2)
509    ["pri1"]=>
510    int(3)
511    ["imp1"]=>
512    int(4)
513    ["dyn1"]=>
514    int(5)
515  }
516  ["$this"]=>
517  object(ArrayObjectEx)#%d (5) {
518    ["pub1"]=>
519    int(1)
520    ["pro1":protected]=>
521    int(2)
522    ["pri1":"ArrayObjectEx":private]=>
523    int(3)
524    ["imp1"]=>
525    int(4)
526    ["dyn1"]=>
527    int(5)
528  }
529}
530ArrayObjectEx::show()
531ArrayObjectEx::getIterator()
532ArrayIteratorEx::__construct()
533ArrayIteratorEx::dump()
534array(3) {
535  ["Flags"]=>
536  int(0)
537  ["OVars"]=>
538  array(4) {
539    ["pub1"]=>
540    int(1)
541    ["pro1"]=>
542    int(2)
543    ["imp1"]=>
544    int(4)
545    ["dyn1"]=>
546    int(5)
547  }
548  ["$this"]=>
549  object(ArrayIteratorEx)#%d (6) {
550    ["pub2"]=>
551    int(1)
552    ["pro2":protected]=>
553    int(2)
554    ["pri2":"ArrayIteratorEx":private]=>
555    int(3)
556    ["imp2"]=>
557    int(4)
558    ["dyn2"]=>
559    int(5)
560    ["storage":"ArrayIterator":private]=>
561    object(ArrayObjectEx)#%d (5) {
562      ["pub1"]=>
563      int(1)
564      ["pro1":protected]=>
565      int(2)
566      ["pri1":"ArrayObjectEx":private]=>
567      int(3)
568      ["imp1"]=>
569      int(4)
570      ["dyn1"]=>
571      int(5)
572    }
573  }
574}
575array(1) {
576  ["pub1"]=>
577  int(1)
578}
579array(1) {
580  ["imp1"]=>
581  int(4)
582}
583array(1) {
584  ["dyn1"]=>
585  int(5)
586}
587===FOREACH===
588ArrayObjectEx::getIterator()
589ArrayIteratorEx::__construct()
590ArrayIteratorEx::dump()
591array(3) {
592  ["Flags"]=>
593  int(0)
594  ["OVars"]=>
595  array(4) {
596    ["pub1"]=>
597    int(1)
598    ["pro1"]=>
599    int(2)
600    ["imp1"]=>
601    int(4)
602    ["dyn1"]=>
603    int(5)
604  }
605  ["$this"]=>
606  object(ArrayIteratorEx)#%d (6) {
607    ["pub2"]=>
608    int(1)
609    ["pro2":protected]=>
610    int(2)
611    ["pri2":"ArrayIteratorEx":private]=>
612    int(3)
613    ["imp2"]=>
614    int(4)
615    ["dyn2"]=>
616    int(5)
617    ["storage":"ArrayIterator":private]=>
618    object(ArrayObjectEx)#%d (5) {
619      ["pub1"]=>
620      int(1)
621      ["pro1":protected]=>
622      int(2)
623      ["pri1":"ArrayObjectEx":private]=>
624      int(3)
625      ["imp1"]=>
626      int(4)
627      ["dyn1"]=>
628      int(5)
629    }
630  }
631}
632array(1) {
633  ["pub1"]=>
634  int(1)
635}
636array(1) {
637  ["imp1"]=>
638  int(4)
639}
640array(1) {
641  ["dyn1"]=>
642  int(5)
643}
644===PROPERTY===
645int(1)
646bool(false)
647ArrayObjectEx::setFlags(2)
648int(1)
649bool(false)
650int(1)
651bool(false)
652ArrayIteratorEx::setFlags(2)
653int(1)
654bool(true)
655===CHECK===
656ArrayObjectEx::setFlags(1)
657ArrayObjectEx::dump()
658array(3) {
659  ["Flags"]=>
660  int(1)
661  ["OVars"]=>
662  array(5) {
663    ["pub1"]=>
664    int(1)
665    ["pro1"]=>
666    int(2)
667    ["pri1"]=>
668    int(3)
669    ["imp1"]=>
670    int(4)
671    ["dyn1"]=>
672    int(5)
673  }
674  ["$this"]=>
675  object(ArrayObjectEx)#%d (5) {
676    ["pub1"]=>
677    int(1)
678    ["pro1":protected]=>
679    int(2)
680    ["pri1":"ArrayObjectEx":private]=>
681    int(3)
682    ["imp1"]=>
683    int(4)
684    ["dyn1"]=>
685    int(5)
686  }
687}
688ArrayObjectEx::show()
689ArrayObjectEx::getIterator()
690ArrayIteratorEx::__construct()
691ArrayIteratorEx::dump()
692array(3) {
693  ["Flags"]=>
694  int(1)
695  ["OVars"]=>
696  array(5) {
697    ["pub2"]=>
698    int(1)
699    ["pro2"]=>
700    int(2)
701    ["pri2"]=>
702    int(3)
703    ["imp2"]=>
704    int(4)
705    ["dyn2"]=>
706    int(5)
707  }
708  ["$this"]=>
709  object(ArrayIteratorEx)#%d (6) {
710    ["pub2"]=>
711    int(1)
712    ["pro2":protected]=>
713    int(2)
714    ["pri2":"ArrayIteratorEx":private]=>
715    int(3)
716    ["imp2"]=>
717    int(4)
718    ["dyn2"]=>
719    int(5)
720    ["storage":"ArrayIterator":private]=>
721    object(ArrayObjectEx)#%d (5) {
722      ["pub1"]=>
723      int(1)
724      ["pro1":protected]=>
725      int(2)
726      ["pri1":"ArrayObjectEx":private]=>
727      int(3)
728      ["imp1"]=>
729      int(4)
730      ["dyn1"]=>
731      int(5)
732    }
733  }
734}
735array(1) {
736  ["pub1"]=>
737  int(1)
738}
739array(1) {
740  ["imp1"]=>
741  int(4)
742}
743array(1) {
744  ["dyn1"]=>
745  int(5)
746}
747===FOREACH===
748ArrayObjectEx::getIterator()
749ArrayIteratorEx::__construct()
750ArrayIteratorEx::dump()
751array(3) {
752  ["Flags"]=>
753  int(1)
754  ["OVars"]=>
755  array(5) {
756    ["pub2"]=>
757    int(1)
758    ["pro2"]=>
759    int(2)
760    ["pri2"]=>
761    int(3)
762    ["imp2"]=>
763    int(4)
764    ["dyn2"]=>
765    int(5)
766  }
767  ["$this"]=>
768  object(ArrayIteratorEx)#%d (6) {
769    ["pub2"]=>
770    int(1)
771    ["pro2":protected]=>
772    int(2)
773    ["pri2":"ArrayIteratorEx":private]=>
774    int(3)
775    ["imp2"]=>
776    int(4)
777    ["dyn2"]=>
778    int(5)
779    ["storage":"ArrayIterator":private]=>
780    object(ArrayObjectEx)#%d (5) {
781      ["pub1"]=>
782      int(1)
783      ["pro1":protected]=>
784      int(2)
785      ["pri1":"ArrayObjectEx":private]=>
786      int(3)
787      ["imp1"]=>
788      int(4)
789      ["dyn1"]=>
790      int(5)
791    }
792  }
793}
794array(1) {
795  ["pub1"]=>
796  int(1)
797}
798array(1) {
799  ["imp1"]=>
800  int(4)
801}
802array(1) {
803  ["dyn1"]=>
804  int(5)
805}
806===PROPERTY===
807int(1)
808bool(false)
809ArrayObjectEx::setFlags(3)
810int(1)
811bool(false)
812int(1)
813bool(false)
814ArrayIteratorEx::setFlags(3)
815int(1)
816bool(true)
817===DONE===
818