reference/var/functions/empty.xml
4a07033f7ac5ab121357051cc94ec48b9f6f58fc
...
...
@@ -25,14 +25,6 @@
25
25
<para>
26
26
Variable to be checked
27
27
</para>
28
-
<note>
29
-
<para>
30
-
Prior to PHP 5.5, <function>empty</function> only supports variables;
31
-
anything else will result in a parse error. In other words, the
32
-
following will not work: <command>empty(trim($name))</command>.
33
-
Instead, use <command>trim($name) == false</command>.
34
-
</para>
35
-
</note>
36
28
<para>
37
29
No warning is generated if the variable does not exist.
38
30
That means <function>empty</function> is essentially the
...
...
@@ -46,54 +38,9 @@
46
38
<refsect1 role="returnvalues">
47
39
&reftitle.returnvalues;
48
40
<para>
49
-
Returns &false; if <parameter>var</parameter> exists and has a non-empty, non-zero value.
50
-
Otherwise returns &true;.
51
-
</para>
52
-
<para>
53
-
The following values are considered to be empty:
54
-
<simplelist>
55
-
<member><literal>""</literal> (an empty string)</member>
56
-
<member><literal>0</literal> (0 as an integer)</member>
57
-
<member><literal>0.0</literal> (0 as a float)</member>
58
-
<member><literal>"0"</literal> (0 as a string)</member>
59
-
<member>&null;</member>
60
-
<member>&false;</member>
61
-
<member><literal>array()</literal> (an empty array)</member>
62
-
</simplelist>
63
-
</para>
64
-
</refsect1>
65
-
<refsect1 role="changelog">
66
-
&reftitle.changelog;
67
-
<para>
68
-
<informaltable>
69
-
<tgroup cols="2">
70
-
<thead>
71
-
<row>
72
-
<entry>&Version;</entry>
73
-
<entry>&Description;</entry>
74
-
</row>
75
-
</thead>
76
-
<tbody>
77
-
<row>
78
-
<entry>5.5.0</entry>
79
-
<entry>
80
-
<para>
81
-
<function>empty</function> now supports expressions, rather than only
82
-
variables.
83
-
</para>
84
-
</entry>
85
-
</row>
86
-
<row>
87
-
<entry>5.4.0</entry>
88
-
<entry>
89
-
<para>
90
-
Checking non-numeric offsets of strings returns &true;.
91
-
</para>
92
-
</entry>
93
-
</row>
94
-
</tbody>
95
-
</tgroup>
96
-
</informaltable>
41
+
Returns &true; if <parameter>var</parameter> does not exist or has a value that is empty or equal to zero,
42
+
aka falsey, see <link linkend="language.types.boolean.casting">conversion to boolean</link>.
43
+
Otherwise returns &false;.
97
44
</para>
98
45
</refsect1>
99
46
<refsect1 role="examples">
...
...
@@ -125,10 +72,6 @@ if (isset($var)) {
125
72
</para>
126
73
<example>
127
74
<title><function>empty</function> on String Offsets</title>
128
-
<para>
129
-
PHP 5.4 changes how <function>empty</function> behaves
130
-
when passed string offsets.
131
-
</para>
132
75
<programlisting role="php">
133
76
<![CDATA[
134
77
<?php
...
...
@@ -142,18 +85,7 @@ var_dump(empty($expected_array_got_string['0 Mostel']));
142
85
?>
143
86
]]>
144
87
</programlisting>
145
-
&example.outputs.53;
146
-
<screen>
147
-
<![CDATA[
148
-
bool(false)
149
-
bool(false)
150
-
bool(false)
151
-
bool(false)
152
-
bool(false)
153
-
bool(false)
154
-
]]>
155
-
</screen>
156
-
&example.outputs.54;
88
+
&example.outputs;
157
89
<screen>
158
90
<![CDATA[
159
91
bool(true)
160
92