xref: /PHP-7.0/ext/spl/tests/fixedarray_001.phpt (revision 0a6bcd44)
1--TEST--
2SPL: FixedArray: std operations
3--FILE--
4<?php
5$a = new SplFixedArray(0);
6// errors
7try {
8    $a[0] = "value1";
9} catch (RuntimeException $e) {
10    echo "Exception: ".$e->getMessage()."\n";
11}
12try {
13    var_dump($a["asdf"]);
14} catch (RuntimeException $e) {
15    echo "Exception: ".$e->getMessage()."\n";
16}
17try {
18    unset($a[-1]);
19} catch (RuntimeException $e) {
20    echo "Exception: ".$e->getMessage()."\n";
21}
22$a->setSize(10);
23
24
25$a[0] = "value0";
26$a[1] = "value1";
27$a[2] = "value2";
28$a[3] = "value3";
29$ref = "value4";
30$ref2 =&$ref;
31$a[4] = $ref;
32$ref = "value5";
33
34unset($a[1]);
35
36var_dump($a[0], $a[2], $a[3], $a[4]);
37
38// countable
39
40var_dump(count($a), $a->getSize(), count($a) == $a->getSize());
41
42// clonable
43$b = clone $a;
44$a[0] = "valueNew";
45var_dump($b[0]);
46?>
47===DONE===
48--EXPECTF--
49Exception: Index invalid or out of range
50Exception: Index invalid or out of range
51Exception: Index invalid or out of range
52string(6) "value0"
53string(6) "value2"
54string(6) "value3"
55string(6) "value4"
56int(10)
57int(10)
58bool(true)
59string(6) "value0"
60===DONE===
61