<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/language.attributes.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'language.attributes.classes.php',
    1 => 'Deklaration von Attributklassen',
    2 => 'Deklaration von Attributklassen',
  ),
  'up' => 
  array (
    0 => 'language.attributes.php',
    1 => 'Attribute',
  ),
  'prev' => 
  array (
    0 => 'language.attributes.reflection.php',
    1 => 'Lesen von Attributen mit der Reflection-API',
  ),
  'next' => 
  array (
    0 => 'language.references.php',
    1 => 'Referenzen',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'de',
    'path' => 'language/attributes.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="language.attributes.classes" class="sect1">
   <h2 class="title">Deklaration von Attributklassen</h2>

   <p class="para">
    Es ist empfehlenswert, für jedes Attribut eine eigene Klasse zu definieren.
    Im einfachsten Fall genügt eine leere Klasse, in der das Attribut
    <code class="literal">#[Attribute]</code> deklariert wird. Das Attribut kann mit
    einer <code class="literal">use</code>-Anweisung aus dem globalen Namensraum
    importiert werden.
   </p>

  <div class="example" id="example-1">
   <p><strong>Beispiel #1 Einfache Attributklasse</strong></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">namespace </span><span style="color: #0000BB">Example</span><span style="color: #007700">;<br /><br />use </span><span style="color: #0000BB">Attribute</span><span style="color: #007700">;<br /><br />#[</span><span style="color: #0000BB">Attribute</span><span style="color: #007700">]<br />class </span><span style="color: #0000BB">MyAttribute<br /></span><span style="color: #007700">{<br />}</span></span></code></div>
   </div>

  </div>

  <p class="para">
   Um die Arten der Deklarationen einzuschränken, auf die ein Attribut
   angewendet werden kann, kann eine Bitmaske als erstes Argument an die
   <code class="literal">#[Attribute]</code>-Deklaration übergeben werden.
  </p>

  <div class="example" id="example-2">
   <p><strong>Beispiel #2 Verwendung der Zielspezifikation, um die Verwendung von Attributen zu beschränken</strong></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">namespace </span><span style="color: #0000BB">Example</span><span style="color: #007700">;<br /><br />use </span><span style="color: #0000BB">Attribute</span><span style="color: #007700">;<br /><br />#[</span><span style="color: #0000BB">Attribute</span><span style="color: #007700">(</span><span style="color: #0000BB">Attribute</span><span style="color: #007700">::</span><span style="color: #0000BB">TARGET_METHOD </span><span style="color: #007700">| </span><span style="color: #0000BB">Attribute</span><span style="color: #007700">::</span><span style="color: #0000BB">TARGET_FUNCTION</span><span style="color: #007700">)]<br />class </span><span style="color: #0000BB">MyAttribute<br /></span><span style="color: #007700">{<br />}</span></span></code></div>
    </div>


    <div class="example-contents"><p>
     Wenn <span class="classname"><strong class="classname">MyAttribute</strong></span> für einen anderen Typ deklariert
     wird, wird nun beim Aufruf von
     <span class="function"><a href="reflectionattribute.newinstance.php" class="function">ReflectionAttribute::newInstance()</a></span> eine Exception
     ausgelöst.
    </p></div>
   </div>

   <p class="para">Die folgenden Ziele können angegeben werden:</p>

   <ul class="simplelist">
    <li><strong><code><a href="class.attribute.php#attribute.constants.target-class">Attribute::TARGET_CLASS</a></code></strong></li>
    <li><strong><code><a href="class.attribute.php#attribute.constants.target-function">Attribute::TARGET_FUNCTION</a></code></strong></li>
    <li><strong><code><a href="class.attribute.php#attribute.constants.target-method">Attribute::TARGET_METHOD</a></code></strong></li>
    <li><strong><code><a href="class.attribute.php#attribute.constants.target-property">Attribute::TARGET_PROPERTY</a></code></strong></li>
    <li><strong><code><a href="class.attribute.php#attribute.constants.target-class-constant">Attribute::TARGET_CLASS_CONSTANT</a></code></strong></li>
    <li><strong><code><a href="class.attribute.php#attribute.constants.target-parameter">Attribute::TARGET_PARAMETER</a></code></strong></li>
    <li><strong><code><a href="class.attribute.php#attribute.constants.target-all">Attribute::TARGET_ALL</a></code></strong></li>
   </ul>

   <p class="para">
    Standardmäßig kann ein Attribut nur einmal pro Deklaration verwendet
    werden. Damit ein Attribut wiederholbar ist, muss es in der Bitmaske der
    <code class="literal">#[Attribut]</code>-Deklaration mit dem Flag
    <strong><code><a href="class.attribute.php#attribute.constants.is-repeatable">Attribute::IS_REPEATABLE</a></code></strong> angegeben werden.
   </p>

   <div class="example" id="example-3">
    <p><strong>Beispiel #3 Verwendung von IS_REPEATABLE um ein Attribut mehrfach in einer Deklaration zu erlauben</strong></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">namespace </span><span style="color: #0000BB">Example</span><span style="color: #007700">;<br /><br />use </span><span style="color: #0000BB">Attribute</span><span style="color: #007700">;<br /><br />#[</span><span style="color: #0000BB">Attribute</span><span style="color: #007700">(</span><span style="color: #0000BB">Attribute</span><span style="color: #007700">::</span><span style="color: #0000BB">TARGET_METHOD </span><span style="color: #007700">| </span><span style="color: #0000BB">Attribute</span><span style="color: #007700">::</span><span style="color: #0000BB">TARGET_FUNCTION </span><span style="color: #007700">| </span><span style="color: #0000BB">Attribute</span><span style="color: #007700">::</span><span style="color: #0000BB">IS_REPEATABLE</span><span style="color: #007700">)]<br />class </span><span style="color: #0000BB">MyAttribute<br /></span><span style="color: #007700">{<br />}</span></span></code></div>
    </div>


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