<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/language.enumerations.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'language.enumerations.traits.php',
    1 => 'Traits',
    2 => 'Traits',
  ),
  'up' => 
  array (
    0 => 'language.enumerations.php',
    1 => 'Aufz&auml;hlungen (Enum)',
  ),
  'prev' => 
  array (
    0 => 'language.enumerations.constants.php',
    1 => 'Aufz&auml;hlungen und Konstanten',
  ),
  'next' => 
  array (
    0 => 'language.enumerations.expressions.php',
    1 => 'Enum-Werte in konstanten Ausdr&uuml;cken',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'de',
    'path' => 'language/enumerations.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="language.enumerations.traits" class="sect1">
  <h2 class="title">Traits</h2>

  <p class="para">
   Enums können Traits verwenden, die sich dann genauso verhalten wie in
   Klassen. Hierbei ist zu beachten, dass die in einer Enum verwendeten Traits
   keine Eigenschaften enthalten dürfen, sondern nur Methoden, statische
   Methoden und Konstanten. Ein Trait mit Eigenschaften führt zu einem fatalen
   Fehler.
  </p>

  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">interface </span><span style="color: #0000BB">Colorful<br /></span><span style="color: #007700">{<br />    public function </span><span style="color: #0000BB">color</span><span style="color: #007700">(): </span><span style="color: #0000BB">string</span><span style="color: #007700">;<br />}<br /><br />trait </span><span style="color: #0000BB">Rectangle<br /></span><span style="color: #007700">{<br />    public function </span><span style="color: #0000BB">shape</span><span style="color: #007700">(): </span><span style="color: #0000BB">string </span><span style="color: #007700">{<br />        return </span><span style="color: #DD0000">"Rectangle"</span><span style="color: #007700">;<br />    }<br />}<br /><br />enum </span><span style="color: #0000BB">Suit </span><span style="color: #007700">implements </span><span style="color: #0000BB">Colorful<br /></span><span style="color: #007700">{<br />    use </span><span style="color: #0000BB">Rectangle</span><span style="color: #007700">;<br /><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 />    public function </span><span style="color: #0000BB">color</span><span style="color: #007700">(): </span><span style="color: #0000BB">string<br />    </span><span style="color: #007700">{<br />        return match(</span><span style="color: #0000BB">$this</span><span style="color: #007700">) {<br />            </span><span style="color: #0000BB">Suit</span><span style="color: #007700">::</span><span style="color: #0000BB">Hearts</span><span style="color: #007700">, </span><span style="color: #0000BB">Suit</span><span style="color: #007700">::</span><span style="color: #0000BB">Diamonds </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'Red'</span><span style="color: #007700">,<br />            </span><span style="color: #0000BB">Suit</span><span style="color: #007700">::</span><span style="color: #0000BB">Clubs</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">=&gt; </span><span style="color: #DD0000">'Black'</span><span style="color: #007700">,<br />        };<br />    }<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
  </div>

 </div><?php manual_footer($setup); ?>