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@337450 c90b9560-bf6c-de11-be94-00142212c4b1
234 lines
5.2 KiB
XML
234 lines
5.2 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 01ba7cb60a820f300053a9e2ebdbff8ddb679b8a Maintainer: seros Status: ready -->
|
|
<!-- Reviewed: yes Maintainer: seros -->
|
|
<chapter xml:id="language.types" xmlns="http://docbook.org/ns/docbook">
|
|
<title>Tipos</title>
|
|
|
|
<sect1 xml:id="language.types.intro">
|
|
<title>Introducción</title>
|
|
|
|
<simpara>
|
|
PHP admite ocho tipos primitivos.
|
|
</simpara>
|
|
|
|
<para>
|
|
Cuatro tipos escalares:
|
|
</para>
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>boolean</type>
|
|
</simpara>
|
|
</listitem>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>integer</type>
|
|
</simpara>
|
|
</listitem>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>float</type> (número de punto flotante, también conocido como <type>double</type>)
|
|
</simpara>
|
|
</listitem>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>string</type>
|
|
</simpara>
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
<para>
|
|
Dos tipos compuestos:
|
|
</para>
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>array</type>
|
|
</simpara>
|
|
</listitem>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>object</type>
|
|
</simpara>
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
<para>
|
|
Y finalmente dos tipos especiales:
|
|
</para>
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>resource</type>
|
|
</simpara>
|
|
</listitem>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>NULL</type>
|
|
</simpara>
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
<para>
|
|
Este manual introduce también algunos
|
|
<link linkend="language.pseudo-types">pseudotipos</link> por razones de
|
|
legibilidad:
|
|
</para>
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>mixed</type>
|
|
</simpara>
|
|
</listitem>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>number</type>
|
|
</simpara>
|
|
</listitem>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>callback (también conocido como callable)</type>
|
|
</simpara>
|
|
</listitem>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>array|object</type>
|
|
</simpara>
|
|
</listitem>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>void</type>
|
|
</simpara>
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
<para>
|
|
Y la pseudo variable <parameter>$...</parameter>.
|
|
</para>
|
|
|
|
<simpara>
|
|
Puede que existan aún algunas referencias al tipo "double" en el manual. Considere
|
|
al tipo double como float; los dos nombres existen sólo por razones históricas.
|
|
</simpara>
|
|
|
|
<simpara>
|
|
El tipo de una variable usualmente no lo declara el programador; al contrario, es
|
|
decidido en tiempo de ejecución por PHP dependiendo del contexto en el que se emplea
|
|
dicha variable.
|
|
</simpara>
|
|
|
|
<note>
|
|
<simpara>
|
|
Para comprobar el tipo y el valor de una
|
|
<link linkend="language.expressions">expresión</link>,
|
|
utilice la función <function>var_dump</function>.
|
|
</simpara>
|
|
|
|
<para>
|
|
Para obtener una representación legible por humanos de un tipo con propósitos de depuración, use
|
|
la función <function>gettype</function>. Para comprobar un cierto tipo,
|
|
<emphasis>no</emphasis> emplee <function>gettype</function>, si no las funciones
|
|
<literal>is_<replaceable>tipo</replaceable></literal>. Algunos
|
|
ejemplos:
|
|
</para>
|
|
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$un_bool = TRUE; // un valor booleano
|
|
$un_str = "foo"; // una cadena de caracteres
|
|
$un_str2 = 'foo'; // una cadena de caracteres
|
|
$un_int = 12; // un número entero
|
|
|
|
echo gettype($un_bool); // imprime: boolean
|
|
echo gettype($un_str); // imprime: string
|
|
|
|
// Si este valor es un entero, incrementarlo en cuatro
|
|
if (is_int($un_int)) {
|
|
$un_int += 4;
|
|
}
|
|
|
|
// Si $un_bool es una cadena, imprimirla
|
|
// (no imprime nada)
|
|
if (is_string($un_bool)) {
|
|
echo "Cadena: $un_bool";
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</informalexample>
|
|
</note>
|
|
|
|
<simpara>
|
|
Para forzar la conversión de una variable a un cierto tipo, puede <link
|
|
linkend="language.types.typecasting">amoldar</link> la variable o usar la
|
|
función <function>settype</function> con ella.
|
|
</simpara>
|
|
|
|
<simpara>
|
|
Observe que una variable puede ser evaluada con valores diferentes en ciertas
|
|
situaciones, dependiendo del tipo que posea en cada momento. Para más información,
|
|
lea la sección sobre <link linkend="language.types.type-juggling">Manipulación
|
|
de tipos</link>. <link linkend="types.comparisons">Las tablas de comparación de
|
|
tipos</link> pueden resultar útiles también, ya que muestran ejemplos de varias
|
|
comparaciones relacionadas con tipos.
|
|
</simpara>
|
|
</sect1>
|
|
|
|
&language.types.boolean;
|
|
&language.types.integer;
|
|
&language.types.float;
|
|
&language.types.string;
|
|
&language.types.array;
|
|
&language.types.object;
|
|
&language.types.resource;
|
|
&language.types.null;
|
|
&language.types.callable;
|
|
&language.types.pseudo-types;
|
|
&language.types.type-juggling;
|
|
|
|
</chapter>
|
|
|
|
<!-- 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
|
|
--> |