xref: /PHP-7.3/Zend/tests/empty_str_offset.phpt (revision 30156d58)
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 ---
101bool(false)
102bool(true)
103bool(true)
104bool(false)
105bool(false)
106bool(false)
107bool(false)
108bool(false)
109bool(true)
110- array ---
111bool(true)
112bool(true)
113- object ---
114bool(true)
115- resource ---
116bool(true)
117done
118