mirror of
https://github.com/php/doc-es.git
synced 2026-03-25 16:02:13 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@337452 c90b9560-bf6c-de11-be94-00142212c4b1
180 lines
4.7 KiB
XML
180 lines
4.7 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 7f79d8835b340397d2fd6633da4d52dc535e8677 Maintainer: lboshell Status: ready -->
|
|
<!-- Reviewed: yes Maintainer: seros -->
|
|
<sect1 xml:id="language.types.boolean">
|
|
<title>Booleanos</title>
|
|
|
|
<simpara>
|
|
Este es el tipo más simple. Un <type>boolean</type> expresa un valor que indica
|
|
verdad. Puede ser &true; (verdadero) o &false; (falso).
|
|
</simpara>
|
|
|
|
<sect2 xml:id="language.types.boolean.syntax">
|
|
<title>Sintaxis</title>
|
|
<para>
|
|
Para especificar un literal de tipo <type>boolean</type> se emplean las constantes &true; o
|
|
&false;. Ambas no son susceptibles a mayúsculas y minúsculas.
|
|
</para>
|
|
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$foo = True; // asigna el valor TRUE a $foo
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</informalexample>
|
|
|
|
<para>
|
|
Usualmente, el resultado de un <link linkend="language.operators">operador</link>
|
|
que devuelve un valor de tipo <type>boolean</type> es pasado a una
|
|
<link linkend="language.control-structures">estructura de control</link>.
|
|
</para>
|
|
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// == es un operador que comprueba la
|
|
// igualdad y devuelve un booleano
|
|
if ($accion == "mostrar_version") {
|
|
echo "La versión es 1.23";
|
|
}
|
|
|
|
// esto no es necesario...
|
|
if ($mostrar_separadores == TRUE) {
|
|
echo "<hr>\n";
|
|
}
|
|
|
|
// ...porque se puede escribir simplemente:
|
|
if ($mostrar_separadores) {
|
|
echo "<hr>\n";
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</informalexample>
|
|
</sect2>
|
|
|
|
<sect2 xml:id="language.types.boolean.casting">
|
|
<title>Conversión a booleano</title>
|
|
|
|
<simpara>
|
|
Para convertir explícitamente un valor al tipo <type>boolean</type>, use los
|
|
amoldamientos <literal>(bool)</literal> o <literal>(boolean)</literal>. Sin embargo,
|
|
en la mayoría de casos es innecesario el amoldamiento, ya que un valor será convertido
|
|
automáticamente si un operador, función o estructura de control requiere un
|
|
argumento de tipo <type>boolean</type>.
|
|
</simpara>
|
|
|
|
<simpara>
|
|
Véase también la <link linkend="language.types.type-juggling">Manipulación de
|
|
tipos</link>.
|
|
</simpara>
|
|
|
|
<para>
|
|
Cuando se realizan conversiones a <type>boolean</type>, los siguientes valores se
|
|
consideran &false;:
|
|
</para>
|
|
|
|
<itemizedlist>
|
|
<listitem>
|
|
<simpara>
|
|
el <link linkend="language.types.boolean">boolean</link> &false; mismo
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
el <link linkend="language.types.integer">integer</link> 0 (cero)
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
el <link linkend="language.types.float">float</link> 0.0 (cero)
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
el valor <link linkend="language.types.string">string</link> vacío, y el
|
|
<link linkend="language.types.string">string</link> "0"
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
un <link linkend="language.types.array">array</link> con cero elementos
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
un <link linkend="language.types.object">object</link> con cero variables
|
|
miembro (sólo en PHP 4)
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
el tipo especial <link linkend="language.types.null">NULL</link> (incluidas
|
|
variables no establecidas)
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>objetos <link linkend="ref.simplexml">SimpleXML</link> creados desde etiquetas
|
|
vacías
|
|
</simpara>
|
|
</listitem>
|
|
</itemizedlist>
|
|
|
|
<para>
|
|
Cualquier otro valor se considera como &true; (incluido cualquier <link
|
|
linkend="language.types.resource">resource</link>).
|
|
</para>
|
|
|
|
<warning>
|
|
<simpara>
|
|
<literal>-1</literal> se considera &true;, como cualquier otro número distinto de cero
|
|
(ya sea negativo o positivo).
|
|
</simpara>
|
|
</warning>
|
|
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
var_dump((bool) ""); // 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>
|
|
</informalexample>
|
|
|
|
</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
|
|
-->
|