xref: /PHP-7.2/ext/spl/tests/dllist_006.phpt (revision 3a4eb3e4)
1--TEST--
2SPL: DoublyLinkedList: ArrayAccess
3--FILE--
4<?php
5$a = new SplDoublyLinkedList();
6$a->push(1);
7$a->push(2);
8$a->push(3);
9
10$a[] = "foo";
11$a[3] = 4;
12
13var_dump($a[0]);
14var_dump($a[1]);
15var_dump($a[2]);
16var_dump($a[3]);
17
18echo "Unsetting..\n";
19var_dump($a[2]);
20unset($a[2]);
21var_dump($a[2]);
22
23
24try {
25    var_dump($a["1"]);
26} catch (OutOfRangeException $e) {
27    echo "Exception: ".$e->getMessage()."\n";
28}
29
30try {
31    var_dump($a["a"]);
32} catch (OutOfRangeException $e) {
33    echo "Exception: ".$e->getMessage()."\n";
34}
35
36try {
37    var_dump($a["0"]);
38} catch (OutOfRangeException $e) {
39    echo "Exception: ".$e->getMessage()."\n";
40}
41
42try {
43    var_dump($a["9"]);
44} catch (OutOfRangeException $e) {
45    echo "Exception: ".$e->getMessage()."\n";
46}
47?>
48===DONE===
49<?php exit(0); ?>
50--EXPECTF--
51int(1)
52int(2)
53int(3)
54int(4)
55Unsetting..
56int(3)
57int(4)
58int(2)
59Exception: Offset invalid or out of range
60int(1)
61Exception: Offset invalid or out of range
62===DONE===
63