Annotation of embedaddon/php/ext/spl/tests/arrayObject_exchangeArray_basic3.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: SPL: ArrayObject::exchangeArray() basic usage with object as underlying data store.
3: --FILE--
4: <?php
5:
6: class C {
7: public $pub1 = 'public1';
8: }
9:
10: echo "--> exchangeArray() with objects:\n";
11: $original = new C;
12: $ao = new ArrayObject($original);
13: $swapIn = new C;
14: try {
15: $copy = $ao->exchangeArray($swapIn);
16: $copy['addedToCopy'] = 'added To Copy';
17: } catch (Exception $e) {
18: echo "Exception:" . $e->getMessage() . "\n";
19: }
20: $swapIn->addedToSwapIn = 'added To Swap-In';
21: $original->addedToOriginal = 'added To Original';
22: var_dump($ao, $original, $swapIn, $copy);
23:
24:
25: echo "\n\n--> exchangeArray() with no arg:\n";
26: unset($original, $ao, $swapIn, $copy);
27: $original = new C;
28: $ao = new ArrayObject($original);
29: try {
30: $copy = $ao->exchangeArray();
31: $copy['addedToCopy'] = 'added To Copy';
32: } catch (Exception $e) {
33: echo "Exception:" . $e->getMessage() . "\n";
34: }
35: $original->addedToOriginal = 'added To Original';
36: var_dump($ao, $original, $copy);
37:
38: echo "\n\n--> exchangeArray() with bad arg type:\n";
39: unset($original, $ao, $swapIn, $copy);
40: $original = new C;
41: $ao = new ArrayObject($original);
42: try {
43: $copy = $ao->exchangeArray(null);
44: $copy['addedToCopy'] = 'added To Copy';
45: } catch (Exception $e) {
46: echo "Exception:" . $e->getMessage() . "\n";
47: }
48: $original->addedToOriginal = 'added To Original';
49: var_dump($ao, $original, $copy);
50:
51: ?>
52: --EXPECTF--
53: --> exchangeArray() with objects:
54: object(ArrayObject)#2 (1) {
55: ["storage":"ArrayObject":private]=>
56: object(C)#3 (2) {
57: ["pub1"]=>
58: string(7) "public1"
59: ["addedToSwapIn"]=>
60: string(16) "added To Swap-In"
61: }
62: }
63: object(C)#1 (2) {
64: ["pub1"]=>
65: string(7) "public1"
66: ["addedToOriginal"]=>
67: string(17) "added To Original"
68: }
69: object(C)#3 (2) {
70: ["pub1"]=>
71: string(7) "public1"
72: ["addedToSwapIn"]=>
73: string(16) "added To Swap-In"
74: }
75: array(2) {
76: ["pub1"]=>
77: string(7) "public1"
78: ["addedToCopy"]=>
79: string(13) "added To Copy"
80: }
81:
82:
83: --> exchangeArray() with no arg:
84:
85: Warning: ArrayObject::exchangeArray() expects exactly 1 parameter, 0 given in %s on line 27
86: object(ArrayObject)#2 (1) {
87: ["storage":"ArrayObject":private]=>
88: object(C)#3 (2) {
89: ["pub1"]=>
90: string(7) "public1"
91: ["addedToOriginal"]=>
92: string(17) "added To Original"
93: }
94: }
95: object(C)#3 (2) {
96: ["pub1"]=>
97: string(7) "public1"
98: ["addedToOriginal"]=>
99: string(17) "added To Original"
100: }
101: array(2) {
102: ["pub1"]=>
103: string(7) "public1"
104: ["addedToCopy"]=>
105: string(13) "added To Copy"
106: }
107:
108:
109: --> exchangeArray() with bad arg type:
110: Exception:Passed variable is not an array or object, using empty array instead
111:
112: Notice: Undefined variable: copy in %s on line 46
113: object(ArrayObject)#3 (1) {
114: ["storage":"ArrayObject":private]=>
115: object(C)#2 (2) {
116: ["pub1"]=>
117: string(7) "public1"
118: ["addedToOriginal"]=>
119: string(17) "added To Original"
120: }
121: }
122: object(C)#2 (2) {
123: ["pub1"]=>
124: string(7) "public1"
125: ["addedToOriginal"]=>
126: string(17) "added To Original"
127: }
128: NULL
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>