xref: /PHP-8.4/Zend/tests/isset_str_offset.phpt (revision b8e380ab)
1--TEST--
2Testing isset with string offsets
3--FILE--
4<?php
5
6print "- isset ---\n";
7
8$str = "test0123";
9
10var_dump(isset($str[-1]));
11var_dump(isset($str[-10]));
12var_dump(isset($str[0]));
13var_dump(isset($str[1]));
14var_dump(isset($str[4])); // 0
15var_dump(isset($str[5])); // 1
16var_dump(isset($str[8]));
17var_dump(isset($str[10000]));
18// non-numeric offsets
19print "- string literal ---\n";
20var_dump(isset($str['-1'])); // 3
21var_dump(isset($str['-10']));
22var_dump(isset($str['0']));
23var_dump(isset($str['1']));
24var_dump(isset($str['4'])); // 0
25var_dump(isset($str['1.5']));
26var_dump(isset($str['good']));
27var_dump(isset($str['3 and a half']));
28print "- string variable ---\n";
29var_dump(isset($str[$key = '-1'])); // 3
30var_dump(isset($str[$key = '-10']));
31var_dump(isset($str[$key = '0']));
32var_dump(isset($str[$key = '1']));
33var_dump(isset($str[$key = '4'])); // 0
34var_dump(isset($str[$key = '1.5']));
35var_dump(isset($str[$key = 'good']));
36var_dump(isset($str[$key = '3 and a half']));
37print "- bool ---\n";
38var_dump(isset($str[true]));
39var_dump(isset($str[false]));
40var_dump(isset($str[false][true]));
41print "- null ---\n";
42var_dump(isset($str[null]));
43print "- double ---\n";
44var_dump(isset($str[-1.1]));
45var_dump(isset($str[-10.5]));
46var_dump(isset($str[-0.8]));
47var_dump(isset($str[-0.1]));
48var_dump(isset($str[0.2]));
49var_dump(isset($str[0.9]));
50var_dump(isset($str[M_PI]));
51var_dump(isset($str[100.5001]));
52print "- array ---\n";
53var_dump(isset($str[array()]));
54var_dump(isset($str[array(1,2,3)]));
55print "- object ---\n";
56var_dump(isset($str[new stdClass()]));
57print "- resource ---\n";
58$f = fopen(__FILE__, 'r');
59var_dump(isset($str[$f]));
60print "done\n";
61
62?>
63--EXPECTF--
64- isset ---
65bool(true)
66bool(false)
67bool(true)
68bool(true)
69bool(true)
70bool(true)
71bool(false)
72bool(false)
73- string literal ---
74bool(true)
75bool(false)
76bool(true)
77bool(true)
78bool(true)
79bool(false)
80bool(false)
81bool(false)
82- string variable ---
83bool(true)
84bool(false)
85bool(true)
86bool(true)
87bool(true)
88bool(false)
89bool(false)
90bool(false)
91- bool ---
92bool(true)
93bool(true)
94bool(false)
95- null ---
96bool(true)
97- double ---
98
99Deprecated: Implicit conversion from float -1.1 to int loses precision in %s on line %d
100bool(true)
101
102Deprecated: Implicit conversion from float -10.5 to int loses precision in %s on line %d
103bool(false)
104
105Deprecated: Implicit conversion from float -0.8 to int loses precision in %s on line %d
106bool(true)
107
108Deprecated: Implicit conversion from float -0.1 to int loses precision in %s on line %d
109bool(true)
110
111Deprecated: Implicit conversion from float 0.2 to int loses precision in %s on line %d
112bool(true)
113
114Deprecated: Implicit conversion from float 0.9 to int loses precision in %s on line %d
115bool(true)
116
117Deprecated: Implicit conversion from float 3.141592653589793 to int loses precision in %s on line %d
118bool(true)
119
120Deprecated: Implicit conversion from float 100.5001 to int loses precision in %s on line %d
121bool(false)
122- array ---
123bool(false)
124bool(false)
125- object ---
126bool(false)
127- resource ---
128bool(false)
129done
130