xref: /PHP-8.2/Zend/tests/offset_array.phpt (revision b8e380ab)
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)
37
38Deprecated: Implicit conversion from float 0.0836 to int loses precision in %s on line %d
39int(1)
40
41Warning: Undefined array key "" in %s on line %d
42NULL
43
44Warning: Undefined array key "run away" in %s on line %d
45NULL
46int(2)
47int(1)
48
49Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
50int(%d)
51Illegal offset type
52Illegal offset type
53Done
54