-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathboolean.xml
More file actions
158 lines (142 loc) · 4.78 KB
/
boolean.xml
File metadata and controls
158 lines (142 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: fee54c7c435a1664a7a8b0e7b7de7cec4a084c45 Maintainer: PhilDaiguille Status: ready -->
<!-- Reviewed: no Maintainer: Marqitos -->
<sect1 xml:id="language.types.boolean">
<title>Booleano</title>
<simpara>
El tipo <type>bool</type> solo posee dos valores y se utiliza para expresar un valor de verdad. Puede ser &true; o &false;.
</simpara>
<sect2 xml:id="language.types.boolean.syntax">
<title>Sintaxis</title>
<para>
Para especificar un <type>bool</type> literal, utilice la constante &true; o &false;. Ambas son insensibles a mayúsculas y minúsculas.
</para>
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$foo = true; // asigna el valor TRUE a $foo
?>
]]>
</programlisting>
</informalexample>
<para>
Típicamente, el resultado de un <link linkend="language.operators">operador</link> que devuelve un <type>bool</type>, pasado luego a una <link linkend="language.control-structures">estructura de control</link>.
</para>
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$action = "show_version";
$show_separators = true;
// == es un operador que prueba
// la igualdad y devuelve un booleano
if ($action == "show_version") {
echo "La versión es 1.23";
}
// esto no es necesario...
if ($show_separators == TRUE) {
echo "<hr>\n";
}
// ...en su lugar, se puede utilizar, con el mismo significado:
if ($show_separators) {
echo "<hr>\n";
}
?>
]]>
</programlisting>
</informalexample>
</sect2>
<sect2 xml:id="language.types.boolean.casting">
<title>Conversión en booleano</title>
<simpara>
Para convertir explícitamente un valor en <type>bool</type>, utilice el cast <literal>(bool)</literal>. Generalmente, esto no es necesario porque cuando un valor se utiliza en un contexto lógico, se interpretará automáticamente como un valor de tipo <type>bool</type>. Para más información, ver la página <link linkend="language.types.type-juggling">Type Juggling</link>.
</simpara>
<para>
Al convertir en <type>bool</type>, los siguientes valores son considerados como &false;:
</para>
<itemizedlist>
<listitem>
<simpara>
el <link linkend="language.types.boolean">booleano</link> &false;, en sí mismo
</simpara>
</listitem>
<listitem>
<simpara>
el <link linkend="language.types.integer">entero</link> <literal>0</literal> (cero)
</simpara>
</listitem>
<listitem>
<simpara>
los <link linkend="language.types.float">números de punto flotante</link> <literal>0.0</literal> y <literal>-0.0</literal> (cero)
</simpara>
</listitem>
<listitem>
<simpara>
la <link linkend="language.types.string">cadena</link> vacía <literal>""</literal>, y la <link linkend="language.types.string">cadena</link> <literal>"0"</literal>
</simpara>
</listitem>
<listitem>
<simpara>
un <link linkend="language.types.array">array</link> sin elementos
</simpara>
</listitem>
<listitem>
<simpara>
el tipo unidad <link linkend="language.types.null">NULL</link> (incluyendo variables no definidas)
</simpara>
</listitem>
<listitem>
<simpara>
los objetos internos que sobrecargan su comportamiento de casting en booleano. Por ejemplo: los <link linkend="ref.simplexml">objetos SimpleXML</link> creados a partir de elementos vacíos sin atributos, o los objetos <classname>GMP</classname> que representan el valor <literal>0</literal>.
</simpara>
</listitem>
</itemizedlist>
<para>
Todos los demás valores son considerados como &true; (incluyendo los <link linkend="language.types.resource">recursos</link> y <constant>NAN</constant>).
</para>
<warning>
<simpara>
<literal>-1</literal> es considerado como &true;, como todos los números diferentes de cero (negativos o positivos) !
</simpara>
</warning>
<example>
<title>Conversión en booleano</title>
<programlisting role="php">
<![CDATA[
<?php
var_dump((bool) ""); // bool(false)
var_dump((bool) "0"); // bool(false)
var_dump((bool) 1); // bool(true)
var_dump((bool) -2); // bool(true)
var_dump((bool) "foo"); // bool(true)
var_dump((bool) 2.3e5); // bool(true)
var_dump((bool) array(12)); // bool(true)
var_dump((bool) array()); // bool(false)
var_dump((bool) "false"); // bool(true)
?>
]]>
</programlisting>
</example>
</sect2>
</sect1>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->