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(1) {
102  ["addedToCopy"]=>
103  string(13) "added To Copy"
104}
105
106
107--> exchangeArray() with bad arg type:
108Exception:Passed variable is not an array or object
109
110Notice: Undefined variable: copy in %s on line 46
111object(ArrayObject)#3 (1) {
112  ["storage":"ArrayObject":private]=>
113  object(C)#2 (2) {
114    ["pub1"]=>
115    string(7) "public1"
116    ["addedToOriginal"]=>
117    string(17) "added To Original"
118  }
119}
120object(C)#2 (2) {
121  ["pub1"]=>
122  string(7) "public1"
123  ["addedToOriginal"]=>
124  string(17) "added To Original"
125}
126NULL
127