<?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 => 'en',
  ),
  'this' => 
  array (
    0 => 'language.types.enumerations.php',
    1 => 'Enumerations',
    2 => 'Enumerations',
  ),
  'up' => 
  array (
    0 => 'language.types.php',
    1 => 'Types',
  ),
  'prev' => 
  array (
    0 => 'language.types.object.php',
    1 => 'Objects',
  ),
  'next' => 
  array (
    0 => 'language.types.resource.php',
    1 => 'Resources',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    '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">Enumerations</h2>
 <p class="verinfo">(PHP 8 &gt;= 8.1.0)</p>

 <div class="sect2" id="language.types.enumerations.basics">
  <h3 class="title">Basic Enumerations</h3>

  <p class="para">
   Enumerations are a restricting layer on top of classes and class constants,
   intended to provide a way to define a closed set of possible values for a 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">
   For a full discussion, see the
   <a href="language.enumerations.php" class="link">Enumerations</a> chapter.
  </p>

 </div>
 
 <div class="sect2" id="language.types.enumerations.casting">
  <h3 class="title">Casting</h3>
  
  <p class="para">
   If an <span class="type">enum</span> is converted to an <span class="type"><a href="language.types.object.php" class="type object">object</a></span>, it is not
   modified. If an <span class="type">enum</span> is converted to an <span class="type"><a href="language.types.array.php" class="type array">array</a></span>,
   an array with a single <code class="literal">name</code> key (for Pure enums) or
   an array with both <code class="literal">name</code> and <code class="literal">value</code> keys
   (for Backed enums) is created.  All other cast types will result in an error.
  </p>
 </div>
</div><?php manual_footer($setup); ?>