xref: /PHP-8.0/ext/spl/tests/array_001.phpt (revision c48b745f)
1--TEST--
2SPL: ArrayObject
3--FILE--
4<?php
5
6$ar = array(0=>0, 1=>1);
7$ar = new ArrayObject($ar);
8
9var_dump($ar);
10
11$ar[2] = 2;
12var_dump($ar[2]);
13var_dump($ar["3"] = 3);
14
15var_dump(array_merge((array)$ar, array(4=>4, 5=>5)));
16
17var_dump($ar["a"] = "a");
18
19var_dump($ar);
20var_dump($ar[0]);
21var_dump($ar[6]);
22var_dump($ar["b"]);
23
24unset($ar[1]);
25unset($ar["3"]);
26unset($ar["a"]);
27unset($ar[7]);
28unset($ar["c"]);
29var_dump($ar);
30
31$ar[] = '3';
32$ar[] = 4;
33var_dump($ar);
34
35?>
36--EXPECTF--
37object(ArrayObject)#%d (1) {
38  ["storage":"ArrayObject":private]=>
39  array(2) {
40    [0]=>
41    int(0)
42    [1]=>
43    int(1)
44  }
45}
46int(2)
47int(3)
48array(6) {
49  [0]=>
50  int(0)
51  [1]=>
52  int(1)
53  [2]=>
54  int(2)
55  [3]=>
56  int(3)
57  [4]=>
58  int(4)
59  [5]=>
60  int(5)
61}
62string(1) "a"
63object(ArrayObject)#%d (1) {
64  ["storage":"ArrayObject":private]=>
65  array(5) {
66    [0]=>
67    int(0)
68    [1]=>
69    int(1)
70    [2]=>
71    int(2)
72    [3]=>
73    int(3)
74    ["a"]=>
75    string(1) "a"
76  }
77}
78int(0)
79
80Warning: Undefined array key 6 in %s on line %d
81NULL
82
83Warning: Undefined array key "b" in %s on line %d
84NULL
85
86Warning: Undefined array key 7 in %s on line %d
87
88Warning: Undefined array key "c" in %s on line %d
89object(ArrayObject)#%d (1) {
90  ["storage":"ArrayObject":private]=>
91  array(2) {
92    [0]=>
93    int(0)
94    [2]=>
95    int(2)
96  }
97}
98object(ArrayObject)#%d (1) {
99  ["storage":"ArrayObject":private]=>
100  array(4) {
101    [0]=>
102    int(0)
103    [2]=>
104    int(2)
105    [4]=>
106    string(1) "3"
107    [5]=>
108    int(4)
109  }
110}
111