-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathtypes.xml
More file actions
155 lines (141 loc) · 5.15 KB
/
types.xml
File metadata and controls
155 lines (141 loc) · 5.15 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
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: e587d0655e426f97b3fcb431453da5030e743b23 Maintainer: PhilDaiguille Status: ready -->
<!-- Reviewed: no -->
<!-- CREDITS: DAnnebicque -->
<chapter xml:id="language.types" xmlns="http://docbook.org/ns/docbook" annotations="interactive">
<title>Los tipos</title>
<sect1 xml:id="language.types.intro">
<title>Introducción</title>
<para>
En PHP, cada expresión tiene uno de los siguientes tipos integrados según su valor:
<itemizedlist>
<listitem><simpara><type>null</type></simpara></listitem>
<listitem><simpara><type>bool</type></simpara></listitem>
<listitem><simpara><type>int</type></simpara></listitem>
<listitem><simpara><type>float</type> (número de punto flotante)</simpara></listitem>
<listitem><simpara><type>string</type></simpara></listitem>
<listitem><simpara><type>array</type></simpara></listitem>
<listitem><simpara><type>object</type></simpara></listitem>
<listitem><simpara><type>callable</type></simpara></listitem>
<listitem><simpara><type>resource</type></simpara></listitem>
</itemizedlist>
</para>
<para>
PHP es un lenguaje de tipado dinámico, lo que significa que, por omisión, no es necesario especificar el tipo de una variable, ya que esto se determinará en tiempo de ejecución. Sin embargo, es posible tipar estáticamente ciertos aspectos del lenguaje utilizando las
<link linkend="language.types.declarations">declaraciones de tipo</link>.
Los diferentes tipos soportados por el sistema de tipos de PHP están disponibles en la
<link linkend="language.types.type-system">página del sistema de tipos</link>.
</para>
<para>
Los tipos limitan el tipo de operaciones que pueden realizarse sobre ellos.
Sin embargo, si una expresión/variable se utiliza en una operación que su tipo no soporta, PHP intentará
<link linkend="language.types.type-juggling">manipular el tipo</link> en un tipo compatible con la operación.
Este proceso depende del contexto en el que se utiliza el valor.
Para más información, consulte la sección sobre la
<link linkend="language.types.type-juggling">manipulación de tipos</link>.
</para>
<tip>
<simpara>
<link linkend="types.comparisons">Las tablas de comparación de tipos</link>
pueden ser también útiles, ya que se presentan diversos ejemplos de comparación entre valores de diferentes tipos.
</simpara>
</tip>
<note>
<simpara>
Es posible forzar la evaluación de una expresión a un cierto tipo utilizando un
<link linkend="language.types.typecasting">type casting</link>.
Una variable también puede ser convertida en el lugar utilizando la función
<function>settype</function>.
</simpara>
</note>
<para>
Para verificar el tipo y el valor de una
<link linkend="language.expressions">expresión</link>, utilice la función
<function>var_dump</function>.
Para recuperar el tipo de una
<link linkend="language.expressions">expresión</link>,
utilice la función <function>get_debug_type</function>.
Sin embargo, para verificar si una expresión es de un cierto tipo, utilice mejor las funciones
<!-- TODO When PhD support is there: <function>is_<replaceable>type</replaceable></function> -->
<literal>is_<replaceable>type</replaceable></literal>.
<example>
<title>Tipos Diferentes</title>
<programlisting role="php">
<![CDATA[
<?php
$a_bool = TRUE; // un booleano
$a_str = "foo"; // un string
$a_str2 = 'foo'; // un string
$an_int = 12; // un integer
echo gettype($a_bool); // muestra: boolean
echo gettype($a_str); // muestra: string
// Si es un integer, incrementa en 4
if (is_int($an_int)) {
$an_int += 4;
}
// Si $a_bool es un string, se muestra
if (is_string($a_bool)) {
echo "String: $a_bool";
}
?>
]]>
</programlisting>
&example.outputs.8;
<screen>
<![CDATA[
bool
string
int(16)
]]>
</screen>
</example>
</para>
<note>
<simpara>
Anterior a PHP 8.0.0, cuando la función <function>get_debug_type</function> no está
disponible, la función <function>gettype</function> puede ser utilizada en su lugar.
Sin embargo, no utiliza los nombres de tipo canónicos.
</simpara>
</note>
</sect1>
&language.types.type-system;
&language.types.null;
&language.types.boolean;
&language.types.integer;
&language.types.float;
&language.types.string;
&language.types.numeric-strings;
&language.types.array;
&language.types.object;
&language.types.enumerations;
&language.types.resource;
&language.types.callable;
&language.types.mixed;
&language.types.void;
&language.types.never;
&language.types.relative-class-types;
&language.types.singleton;
&language.types.iterable;
&language.types.declarations;
&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
-->