mirror of
https://github.com/macintoshplus/doc-fr.git
synced 2026-03-25 17:32:07 +01:00
207 lines
4.6 KiB
XML
207 lines
4.6 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 9fe810352095922a68ce2807745a9bc35c0afe1f Maintainer: yannick Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
<!-- CREDITS: DAnnebicque -->
|
|
<chapter xml:id="language.types" xmlns="http://docbook.org/ns/docbook">
|
|
<title>Les types</title>
|
|
|
|
<sect1 xml:id="language.types.intro">
|
|
<title>Introduction</title>
|
|
|
|
<simpara>
|
|
PHP supporte 10 types basiques.
|
|
</simpara>
|
|
|
|
<para>
|
|
4 types scalaires :
|
|
</para>
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>bool</type>
|
|
</simpara>
|
|
</listitem>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>int</type>
|
|
</simpara>
|
|
</listitem>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>float</type> (nombre à virgule flottante, i.e. <type>double</type>)
|
|
</simpara>
|
|
</listitem>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>string</type>
|
|
</simpara>
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
<para>
|
|
4 types composés :
|
|
</para>
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>array</type>
|
|
</simpara>
|
|
</listitem>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>object</type>
|
|
</simpara>
|
|
</listitem>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>callable</type>
|
|
</simpara>
|
|
</listitem>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>iterable</type>
|
|
</simpara>
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
<para>
|
|
Et finalement, 2 types spéciaux :
|
|
</para>
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>resource</type>
|
|
</simpara>
|
|
</listitem>
|
|
|
|
<listitem>
|
|
<simpara>
|
|
<type>NULL</type>
|
|
</simpara>
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
<simpara>
|
|
Ce manuel peut toutefois contenir des références au type "double".
|
|
Considérez ce type comme étant un type "float". Les deux noms n'existent
|
|
que pour des raisons historiques.
|
|
</simpara>
|
|
|
|
<simpara>
|
|
Le type d'une variable n'est pas toujours défini par le programmeur ;
|
|
il peut être défini par PHP au moment de l'exécution, suivant le contexte
|
|
dans lequel la variable est utilisée.
|
|
</simpara>
|
|
|
|
<note>
|
|
<simpara>
|
|
Pour vérifier le type et la valeur d'une
|
|
<link linkend="language.expressions">expression</link>, utilisez la fonction
|
|
<function>var_dump</function>.
|
|
</simpara>
|
|
|
|
<para>
|
|
Pour afficher une représentation humainement lisible d'un type aux fins de débogage,
|
|
utilisez la fonction <function>gettype</function>.
|
|
Pour vérifier un certain type, n'utilisez <emphasis>pas</emphasis> la fonction
|
|
<function>gettype</function>, mais plutôt les fonctions
|
|
<literal>is_<replaceable>type</replaceable></literal>. Voici quelques exemples :
|
|
</para>
|
|
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$a_bool = TRUE; // un booléen
|
|
$a_str = "foo"; // une chaîne de caractères
|
|
$a_str2 = 'foo'; // une chaîne de caractères
|
|
$an_int = 12; // un entier
|
|
|
|
echo gettype($a_bool); // affiche : boolean
|
|
echo gettype($a_str); // affiche : string
|
|
|
|
// Si c'est un entier, incrément de 4
|
|
if (is_int($an_int)) {
|
|
$an_int += 4;
|
|
}
|
|
|
|
// Si $a_bool est une chaîne de caractères, on l'affiche
|
|
if (is_string($a_bool)) {
|
|
echo "String: $a_bool";
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</informalexample>
|
|
</note>
|
|
|
|
<simpara>
|
|
Pour forcer la conversion d'une variable en un certain type, vous
|
|
pouvez transtyper (<link linkend="language.types.typecasting">cast</link>)
|
|
la variable ou utiliser la fonction <function>settype</function>.
|
|
</simpara>
|
|
|
|
<simpara>
|
|
Notez qu'une variable peut être évaluée avec différentes valeurs dans
|
|
certaines situations, suivant son type à un moment donné. Pour plus
|
|
d'informations, lisez la section sur le
|
|
<link linkend="language.types.type-juggling">transtypage</link>.
|
|
<link linkend="types.comparisons">La table de comparaison des types</link>
|
|
peut également être très utile, montrant différents exemples.
|
|
</simpara>
|
|
</sect1>
|
|
|
|
&language.types.boolean;
|
|
&language.types.integer;
|
|
&language.types.float;
|
|
&language.types.string;
|
|
&language.types.numeric-strings;
|
|
&language.types.array;
|
|
&language.types.iterable;
|
|
&language.types.object;
|
|
&language.types.enumerations;
|
|
&language.types.resource;
|
|
&language.types.null;
|
|
&language.types.callable;
|
|
&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
|
|
-->
|