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