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