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