1
0
mirror of https://github.com/php/doc-ja.git synced 2026-03-24 07:02:08 +01:00
Files
archived-doc-ja/language/types/enumerations.xml
2023-07-29 12:14:18 +09:00

81 lines
2.0 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: f4609f913fe6bf4a8b41328df9366726208b7e33 Maintainer: mumumu Status: ready -->
<sect1 xml:id="language.types.enumerations">
<title>列挙型 / Enum</title>
<?phpdoc print-version-for="enumerations"?>
<sect2 xml:id="language.types.enumerations.basics">
<title>列挙型の基礎</title>
<para>
列挙型は、クラスやクラス定数に対して、さらに制限を加えたものです。
ある型に対して、取り得る値の限られた集合を定義する方法を提供します。
</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>
完全な説明は、
<link linkend="language.enumerations">列挙型(Enum)</link> を参照ください。
</simpara>
</sect2>
<sect2 xml:id="language.types.enumerations.casting">
<title>キャスト</title>
<para>
列挙型を <type>object</type> にキャストしても、値は変更されません。
列挙型を <type>array</type> にキャストすると、
<literal>name</literal> というキーだけ(Pure Enum の場合)
をもつ配列か、
<literal>name</literal><literal>value</literal>
というキー(Backed Enum の場合) を持つ配列が生成されます。
それ以外のキャストを行っても、エラーが発生します。
</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
-->