xref: /PHP-8.0/Zend/tests/offset_array.phpt (revision c48b745f)
1--TEST--
2using different variables to access array offsets
3--FILE--
4<?php
5
6$arr = array(1,2,3,4,5,6,7,8);
7
8var_dump($arr[1]);
9var_dump($arr[0.0836]);
10var_dump($arr[NULL]);
11var_dump($arr["run away"]);
12
13var_dump($arr[TRUE]);
14var_dump($arr[FALSE]);
15
16$fp = fopen(__FILE__, "r");
17var_dump($arr[$fp]);
18
19$obj = new stdClass;
20try {
21    var_dump($arr[$obj]);
22} catch (Error $e) {
23    echo $e->getMessage(), "\n";
24}
25
26$arr1 = Array(1,2,3);
27try {
28    var_dump($arr[$arr1]);
29} catch (Error $e) {
30    echo $e->getMessage(), "\n";
31}
32
33echo "Done\n";
34?>
35--EXPECTF--
36int(2)
37int(1)
38
39Warning: Undefined array key "" in %s on line %d
40NULL
41
42Warning: Undefined array key "run away" in %s on line %d
43NULL
44int(2)
45int(1)
46
47Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
48int(%d)
49Illegal offset type
50Illegal offset type
51Done
52