language/types/boolean.xml
161dde4fe721309398dd324edbf02aec409f127b
...
...
@@ -4,14 +4,14 @@
4
4
<title>Booleans</title>
5
5
6
6
<simpara>
7
-
This is the simplest type. A <type>boolean</type> expresses a truth value. It
8
-
can be either &true; or &false;.
7
+
The <type>bool</type> type only has two values, and is used to express
8
+
a truth value. It can be either &true; or &false;.
9
9
</simpara>
10
10

11
11
<sect2 xml:id="language.types.boolean.syntax">
12
12
<title>Syntax</title>
13
13
<para>
14
-
To specify a <type>boolean</type> literal, use the constants &true; or
14
+
To specify a <type>bool</type> literal, use the constants &true; or
15
15
&false;. Both are case-insensitive.
16
16
</para>
17
17

...
...
@@ -27,7 +27,7 @@ $foo = True; // assign the value TRUE to $foo
27
27

28
28
<para>
29
29
Typically, the result of an <link linkend="language.operators">operator</link>
30
-
which returns a <type>boolean</type> value is passed on to a
30
+
which returns a <type>bool</type> value is passed on to a
31
31
<link linkend="language.control-structures">control structure</link>.
32
32
</para>
33
33

...
...
@@ -60,19 +60,15 @@ if ($show_separators) {
60
60
<title>Converting to boolean</title>
61
61

62
62
<simpara>
63
-
To explicitly convert a value to <type>boolean</type>, use the
64
-
<literal>(bool)</literal> or <literal>(boolean)</literal> casts. However, in
65
-
most cases the cast is unnecessary, since a value will be automatically
66
-
converted if an operator, function or control structure requires a
67
-
<type>boolean</type> argument.
68
-
</simpara>
69
-

70
-
<simpara>
71
-
See also <link linkend="language.types.type-juggling">Type Juggling</link>.
63
+
To explicitly convert a value to <type>bool</type>, use the
64
+
<literal>(bool)</literal> cast. Generally this is not necessary because when
65
+
a value is used in a logical context it will be automatically interpreted
66
+
as a value of type <type>bool</type>. For more information see the
67
+
<link linkend="language.types.type-juggling">Type Juggling</link> page.
72
68
</simpara>
73
69
74
70
<para>
75
-
When converting to <type>boolean</type>, the following values are considered
71
+
When converting to <type>bool</type>, the following values are considered
76
72
&false;:
77
73
</para>
78
74
...
...
@@ -84,18 +80,20 @@ if ($show_separators) {
84
80
</listitem>
85
81
<listitem>
86
82
<simpara>
87
-
the <link linkend="language.types.integer">integer</link> 0 (zero)
83
+
the <link linkend="language.types.integer">integer</link>
84
+
<literal>0</literal> (zero)
88
85
</simpara>
89
86
</listitem>
90
87
<listitem>
91
88
<simpara>
92
-
the <link linkend="language.types.float">float</link> 0.0 (zero)
89
+
the <link linkend="language.types.float">float</link>s
90
+
<literal>0.0</literal> and <literal>-0.0</literal> (zero)
93
91
</simpara>
94
92
</listitem>
95
93
<listitem>
96
94
<simpara>
97
-
the empty <link linkend="language.types.string">string</link>, and the
98
-
<link linkend="language.types.string">string</link> "0"
95
+
the empty <link linkend="language.types.string">string</link> <literal>""</literal>,
96
+
and the <link linkend="language.types.string">string</link> <literal>"0"</literal>
99
97
</simpara>
100
98
</listitem>
101
99
<listitem>
...
...
@@ -105,27 +103,23 @@ if ($show_separators) {
105
103
</listitem>
106
104
<listitem>
107
105
<simpara>
108
-
an <link linkend="language.types.object">object</link> with zero member
109
-
variables (PHP 4 only)
110
-
</simpara>
111
-
</listitem>
112
-
<listitem>
113
-
<simpara>
114
-
the special type <link linkend="language.types.null">NULL</link> (including
106
+
the unit type <link linkend="language.types.null">NULL</link> (including
115
107
unset variables)
116
108
</simpara>
117
109
</listitem>
118
110
<listitem>
119
111
<simpara>
120
-
<link linkend="ref.simplexml">SimpleXML</link> objects created from empty
121
-
tags
112
+
Internal objects that overload their casting behaviour to bool.
113
+
For example: <link linkend="ref.simplexml">SimpleXML</link> objects
114
+
created from empty elements without attributes.
122
115
</simpara>
123
116
</listitem>
124
117
</itemizedlist>
125
118
126
119
<para>
127
-
Every other value is considered &true; (including any
128
-
<link linkend="language.types.resource">resource</link>).
120
+
Every other value is considered &true;
121
+
(including <link linkend="language.types.resource">resource</link>
122
+
and <constant>NAN</constant>).
129
123
</para>
130
124
131
125
<warning>
...
...
@@ -140,6 +134,7 @@ if ($show_separators) {
140
134
<![CDATA[
141
135
<?php
142
136
var_dump((bool) ""); // bool(false)
137
+
var_dump((bool) "0"); // bool(false)
143
138
var_dump((bool) 1); // bool(true)
144
139
var_dump((bool) -2); // bool(true)
145
140
var_dump((bool) "foo"); // bool(true)
...
...
@@ -154,7 +149,6 @@ var_dump((bool) "false"); // bool(true)
154
149

155
150
</sect2>
156
151
</sect1>
157
-

158
152
<!-- Keep this comment at the end of the file
159
153
Local variables:
160
154
mode: sgml
161
155