xref: /PHP-8.4/ext/spl/tests/array_001.phpt (revision 71fb8356)
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
85object(ArrayObject)#%d (1) {
86  ["storage":"ArrayObject":private]=>
87  array(2) {
88    [0]=>
89    int(0)
90    [2]=>
91    int(2)
92  }
93}
94object(ArrayObject)#%d (1) {
95  ["storage":"ArrayObject":private]=>
96  array(4) {
97    [0]=>
98    int(0)
99    [2]=>
100    int(2)
101    [4]=>
102    string(1) "3"
103    [5]=>
104    int(4)
105  }
106}
107