<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/language.types.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'language.types.enumerations.php',
    1 => 'Les &eacute;num&eacute;rations',
    2 => 'Les &eacute;num&eacute;rations',
  ),
  'up' => 
  array (
    0 => 'language.types.php',
    1 => 'Les types',
  ),
  'prev' => 
  array (
    0 => 'language.types.object.php',
    1 => 'Les objets',
  ),
  'next' => 
  array (
    0 => 'language.types.resource.php',
    1 => 'Les ressources',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'language/types/enumerations.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="language.types.enumerations" class="sect1">
 <h2 class="title">Les énumérations</h2>
 <p class="verinfo">(PHP 8 &gt;= 8.1.0)</p>

 <div class="sect2" id="language.types.enumerations.basics">
  <h3 class="title">Les énumérations de base</h3>

  <p class="para">
   Les énumérations constituent une couche restrictive au-dessus des classes et des constantes de classe.
   Elles permettent de définir un ensemble fermé de valeurs possibles pour un type.
  </p>

  <div class="informalexample">
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">enum </span><span style="color: #0000BB">Suit<br /></span><span style="color: #007700">{<br />    case </span><span style="color: #0000BB">Hearts</span><span style="color: #007700">;<br />    case </span><span style="color: #0000BB">Diamonds</span><span style="color: #007700">;<br />    case </span><span style="color: #0000BB">Clubs</span><span style="color: #007700">;<br />    case </span><span style="color: #0000BB">Spades</span><span style="color: #007700">;<br />}<br /><br />function </span><span style="color: #0000BB">do_stuff</span><span style="color: #007700">(</span><span style="color: #0000BB">Suit $s</span><span style="color: #007700">)<br />{<br />    </span><span style="color: #FF8000">// ...<br /></span><span style="color: #007700">}<br /><br /></span><span style="color: #0000BB">do_stuff</span><span style="color: #007700">(</span><span style="color: #0000BB">Suit</span><span style="color: #007700">::</span><span style="color: #0000BB">Spades</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>

  <p class="simpara">
   Pour une description complète, voir le chapitre
   sur <a href="language.enumerations.php" class="link">les énumérations</a>.
  </p>

 </div>

 <div class="sect2" id="language.types.enumerations.casting">
  <h3 class="title">Casting</h3>

  <p class="para">
   Si une <span class="type">enum</span> est convertie en <span class="type"><a href="language.types.object.php" class="type object">object</a></span>, elle n&#039;est pas
   modifiée. Si une <span class="type">enum</span> est convertie en <span class="type"><a href="language.types.array.php" class="type array">array</a></span>,
   un tableau avec une seule clé <code class="literal">name</code> (pour les Pure enums) ou
   un tableau avec les clés <code class="literal">name</code> et <code class="literal">value</code>
   (pour les Backed enums) est créé.  Tous les autres types de conversion entraîneront une erreur.
  </p>
 </div>
</div><?php manual_footer($setup); ?>