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,55 +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 things 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
-
<member><literal>$var;</literal> (a variable declared, but without a value)</member>
63
-
</simplelist>
64
-
</para>
65
-
</refsect1>
66
-
<refsect1 role="changelog">
67
-
&reftitle.changelog;
68
-
<para>
69
-
<informaltable>
70
-
<tgroup cols="2">
71
-
<thead>
72
-
<row>
73
-
<entry>&Version;</entry>
74
-
<entry>&Description;</entry>
75
-
</row>
76
-
</thead>
77
-
<tbody>
78
-
<row>
79
-
<entry>5.5.0</entry>
80
-
<entry>
81
-
<para>
82
-
<function>empty</function> now supports expressions, rather than only
83
-
variables.
84
-
</para>
85
-
</entry>
86
-
</row>
87
-
<row>
88
-
<entry>5.4.0</entry>
89
-
<entry>
90
-
<para>
91
-
Checking non-numeric offsets of strings returns &true;.
92
-
</para>
93
-
</entry>
94
-
</row>
95
-
</tbody>
96
-
</tgroup>
97
-
</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;.
98
44
</para>
99
45
</refsect1>
100
46
<refsect1 role="examples">
...
...
@@ -126,10 +72,6 @@ if (isset($var)) {
126
72
</para>
127
73
<example>
128
74
<title><function>empty</function> on String Offsets</title>
129
-
<para>
130
-
PHP 5.4 changes how <function>empty</function> behaves
131
-
when passed string offsets.
132
-
</para>
133
75
<programlisting role="php">
134
76
<![CDATA[
135
77
<?php
...
...
@@ -143,18 +85,7 @@ var_dump(empty($expected_array_got_string['0 Mostel']));
143
85
?>
144
86
]]>
145
87
</programlisting>
146
-
&example.outputs.53;
147
-
<screen>
148
-
<![CDATA[
149
-
bool(false)
150
-
bool(false)
151
-
bool(false)
152
-
bool(false)
153
-
bool(false)
154
-
bool(false)
155
-
]]>
156
-
</screen>
157
-
&example.outputs.54;
88
+
&example.outputs;
158
89
<screen>
159
90
<![CDATA[
160
91
bool(true)
161
92