1--TEST--
2SPL: ArrayObject::exchangeArray() basic usage with object as underlying data store.
3--FILE--
4<?php
5
6class C {
7	public $pub1 = 'public1';
8}
9
10echo "--> exchangeArray() with objects:\n";
11$original = new C;
12$ao = new ArrayObject($original);
13$swapIn = new C;
14try {
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';
22var_dump($ao, $original, $swapIn, $copy);
23
24
25echo "\n\n--> exchangeArray() with no arg:\n";
26unset($original, $ao, $swapIn, $copy);
27$original = new C;
28$ao = new ArrayObject($original);
29try {
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';
36var_dump($ao, $original, $copy);
37
38echo "\n\n--> exchangeArray() with bad arg type:\n";
39unset($original, $ao, $swapIn, $copy);
40$original = new C;
41$ao = new ArrayObject($original);
42try {
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';
49var_dump($ao, $original, $copy);
50
51?>
52--EXPECTF--
53--> exchangeArray() with objects:
54object(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}
63object(C)#1 (2) {
64  ["pub1"]=>
65  string(7) "public1"
66  ["addedToOriginal"]=>
67  string(17) "added To Original"
68}
69object(C)#3 (2) {
70  ["pub1"]=>
71  string(7) "public1"
72  ["addedToSwapIn"]=>
73  string(16) "added To Swap-In"
74}
75array(2) {
76  ["pub1"]=>
77  string(7) "public1"
78  ["addedToCopy"]=>
79  string(13) "added To Copy"
80}
81
82
83--> exchangeArray() with no arg:
84
85Warning: ArrayObject::exchangeArray() expects exactly 1 parameter, 0 given in %s on line 27
86object(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}
95object(C)#3 (2) {
96  ["pub1"]=>
97  string(7) "public1"
98  ["addedToOriginal"]=>
99  string(17) "added To Original"
100}
101array(2) {
102  ["pub1"]=>
103  string(7) "public1"
104  ["addedToCopy"]=>
105  string(13) "added To Copy"
106}
107
108
109--> exchangeArray() with bad arg type:
110Exception:Passed variable is not an array or object, using empty array instead
111
112Notice: Undefined variable: copy in %s on line 46
113object(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}
122object(C)#2 (2) {
123  ["pub1"]=>
124  string(7) "public1"
125  ["addedToOriginal"]=>
126  string(17) "added To Original"
127}
128NULL
129