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
|
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<sect1 xml:id="language.types.enumerations">
<title>Enumerations</title>
<?phpdoc print-version-for="enumerations"?>
<sect2 xml:id="language.types.enumerations.basics">
<title>Basic Enumerations</title>
<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.
</para>
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
enum Suit
{
case Hearts;
case Diamonds;
case Clubs;
case Spades;
}
function do_stuff(Suit $s)
{
// ...
}
do_stuff(Suit::Spades);
?>
]]>
</programlisting>
</informalexample>
<simpara>
For a full discussion, see the
<link linkend="language.enumerations">Enumerations</link> chapter.
</simpara>
</sect2>
<sect2 xml:id="language.types.enumerations.casting">
<title>Casting</title>
<para>
If an <type>enum</type> is converted to an <type>object</type>, it is not
modified. If an <type>enum</type> is converted to an <type>array</type>,
an array with a single <literal>name</literal> key (for Pure enums) or
an array with both <literal>name</literal> and <literal>value</literal> keys
(for Backed enums) is created. All other cast types will result in an error.
</para>
</sect2>
</sect1>
<!-- 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
-->
|