xref: /PHP-7.1/Zend/tests/isset_str_offset.phpt (revision 370b7039)
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 ---\n";
20var_dump(isset($str['-1']));
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 "- bool ---\n";
29var_dump(isset($str[true]));
30var_dump(isset($str[false]));
31var_dump(isset($str[false][true]));
32print "- null ---\n";
33var_dump(isset($str[null]));
34print "- double ---\n";
35var_dump(isset($str[-1.1]));
36var_dump(isset($str[-10.5]));
37var_dump(isset($str[-0.8]));
38var_dump(isset($str[-0.1]));
39var_dump(isset($str[0.2]));
40var_dump(isset($str[0.9]));
41var_dump(isset($str[M_PI]));
42var_dump(isset($str[100.5001]));
43print "- array ---\n";
44var_dump(isset($str[array()]));
45var_dump(isset($str[array(1,2,3)]));
46print "- object ---\n";
47var_dump(isset($str[new stdClass()]));
48print "- resource ---\n";
49$f = fopen(__FILE__, 'r');
50var_dump(isset($str[$f]));
51print "done\n";
52
53?>
54--EXPECTF--
55- isset ---
56bool(true)
57bool(false)
58bool(true)
59bool(true)
60bool(true)
61bool(true)
62bool(false)
63bool(false)
64- string ---
65bool(true)
66bool(false)
67bool(true)
68bool(true)
69bool(true)
70bool(false)
71bool(false)
72bool(false)
73- bool ---
74bool(true)
75bool(true)
76bool(false)
77- null ---
78bool(true)
79- double ---
80bool(true)
81bool(false)
82bool(true)
83bool(true)
84bool(true)
85bool(true)
86bool(true)
87bool(false)
88- array ---
89bool(false)
90bool(false)
91- object ---
92bool(false)
93- resource ---
94bool(false)
95done
96