<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.reflectionparameter.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'reflectionparameter.getattributes.php',
    1 => 'ReflectionParameter::getAttributes',
    2 => 'Gets Attributes',
  ),
  'up' => 
  array (
    0 => 'class.reflectionparameter.php',
    1 => 'ReflectionParameter',
  ),
  'prev' => 
  array (
    0 => 'reflectionparameter.export.php',
    1 => 'ReflectionParameter::export',
  ),
  'next' => 
  array (
    0 => 'reflectionparameter.getclass.php',
    1 => 'ReflectionParameter::getClass',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/reflection/reflectionparameter/getattributes.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="reflectionparameter.getattributes" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ReflectionParameter::getAttributes</h1>
  <p class="verinfo">(PHP 8)</p><p class="refpurpose"><span class="refname">ReflectionParameter::getAttributes</span> &mdash; <span class="dc-title">Gets Attributes</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-reflectionparameter.getattributes-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>ReflectionParameter::getAttributes</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$name</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$flags</code><span class="initializer"> = 0</span></span>): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>

  <p class="para rdfs-comment">
   Returns all attributes declared on this parameter as an array of <span class="type"><a href="class.reflectionattribute.php" class="type ReflectionAttribute">ReflectionAttribute</a></span>.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-reflectionparameter.getattributes-parameters">
  <h3 class="title">Параметри</h3>
  <dl>
   
<dt><code class="parameter">name</code></dt>
<dd>
 <p class="para">
  Повернути примірники <span class="classname"><a href="class.reflectionattribute.php" class="classname">ReflectionAttribute</a></span> для атрибутів
  з даною назвою класу.
 </p>
</dd>

   
<dt><code class="parameter">flags</code></dt>
<dd>
 <p class="para">
  Прапорці, що визначають, як саме фільтрувати результати, якщо вказано параметр
  <code class="parameter">name</code>.
 </p>
 <p class="para">
  <code class="literal">0</code> (початкове значення) — повертаються результати для
  атрибутів, які мають назву класу <code class="parameter">name</code>.
 </p>
 <p class="para">
  <strong><code><a href="class.reflectionattribute.php#reflectionattribute.constants.is-instanceof">ReflectionAttribute::IS_INSTANCEOF</a></code></strong> — повертаються
  результати для атрибутів із застосуваннями <code class="literal">instanceof</code>.
 </p>
</dd>

  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-reflectionparameter.getattributes-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Array of attributes, as a <span class="classname"><a href="class.reflectionattribute.php" class="classname">ReflectionAttribute</a></span> object.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-reflectionparameter.getattributes-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 Basic usage</strong></p>
    <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">#[</span><span style="color: #0000BB">Attribute</span><span style="color: #007700">]<br />class </span><span style="color: #0000BB">Fruit </span><span style="color: #007700">{<br />}<br /><br />#[</span><span style="color: #0000BB">Attribute</span><span style="color: #007700">]<br />class </span><span style="color: #0000BB">Red </span><span style="color: #007700">{<br />}<br /><br />function </span><span style="color: #0000BB">fruitBasket</span><span style="color: #007700">(<br />   #[</span><span style="color: #0000BB">Fruit</span><span style="color: #007700">]<br />   #[</span><span style="color: #0000BB">Red</span><span style="color: #007700">]<br />   </span><span style="color: #0000BB">string $apple<br /></span><span style="color: #007700">) { }<br /><br /></span><span style="color: #0000BB">$reflection </span><span style="color: #007700">= new </span><span style="color: #0000BB">ReflectionFunction</span><span style="color: #007700">(</span><span style="color: #DD0000">'fruitBasket'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$parameter </span><span style="color: #007700">= </span><span style="color: #0000BB">$reflection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getParameters</span><span style="color: #007700">()[</span><span style="color: #0000BB">0</span><span style="color: #007700">];<br /></span><span style="color: #0000BB">$attributes </span><span style="color: #007700">= </span><span style="color: #0000BB">$parameter</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getAttributes</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">array_map</span><span style="color: #007700">(fn(</span><span style="color: #0000BB">$attribute</span><span style="color: #007700">) =&gt; </span><span style="color: #0000BB">$attribute</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getName</span><span style="color: #007700">(), </span><span style="color: #0000BB">$attributes</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
     <div class="annotation-interactive examplescode"><pre class="examplescode">Array
(
    [0] =&gt; Fruit
    [1] =&gt; Red
)</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Приклад #2 Filtering results by class name</strong></p>
    <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">#[</span><span style="color: #0000BB">Attribute</span><span style="color: #007700">]<br />class </span><span style="color: #0000BB">Fruit </span><span style="color: #007700">{<br />}<br /><br />#[</span><span style="color: #0000BB">Attribute</span><span style="color: #007700">]<br />class </span><span style="color: #0000BB">Red </span><span style="color: #007700">{<br />}<br /><br />function </span><span style="color: #0000BB">fruitBasket</span><span style="color: #007700">(<br />   #[</span><span style="color: #0000BB">Fruit</span><span style="color: #007700">]<br />   #[</span><span style="color: #0000BB">Red</span><span style="color: #007700">]<br />   </span><span style="color: #0000BB">string $apple<br /></span><span style="color: #007700">) { }<br /><br /></span><span style="color: #0000BB">$reflection </span><span style="color: #007700">= new </span><span style="color: #0000BB">ReflectionFunction</span><span style="color: #007700">(</span><span style="color: #DD0000">'fruitBasket'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$parameter </span><span style="color: #007700">= </span><span style="color: #0000BB">$reflection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getParameters</span><span style="color: #007700">()[</span><span style="color: #0000BB">0</span><span style="color: #007700">];<br /></span><span style="color: #0000BB">$attributes </span><span style="color: #007700">= </span><span style="color: #0000BB">$parameter</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getAttributes</span><span style="color: #007700">(</span><span style="color: #DD0000">'Fruit'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">array_map</span><span style="color: #007700">(fn(</span><span style="color: #0000BB">$attribute</span><span style="color: #007700">) =&gt; </span><span style="color: #0000BB">$attribute</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getName</span><span style="color: #007700">(), </span><span style="color: #0000BB">$attributes</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
     <div class="annotation-interactive examplescode"><pre class="examplescode">Array
(
    [0] =&gt; Fruit
)</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-3">
    <p><strong>Приклад #3 Filtering results by class name, with inheritance</strong></p>
    <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">interface </span><span style="color: #0000BB">Color </span><span style="color: #007700">{<br />}<br /><br />#[</span><span style="color: #0000BB">Attribute</span><span style="color: #007700">]<br />class </span><span style="color: #0000BB">Fruit </span><span style="color: #007700">{<br />}<br /><br />#[</span><span style="color: #0000BB">Attribute</span><span style="color: #007700">]<br />class </span><span style="color: #0000BB">Red </span><span style="color: #007700">implements </span><span style="color: #0000BB">Color </span><span style="color: #007700">{<br />}<br /><br />function </span><span style="color: #0000BB">fruitBasket</span><span style="color: #007700">(<br />   #[</span><span style="color: #0000BB">Fruit</span><span style="color: #007700">]<br />   #[</span><span style="color: #0000BB">Red</span><span style="color: #007700">]<br />   </span><span style="color: #0000BB">string $apple<br /></span><span style="color: #007700">) { }<br /><br /></span><span style="color: #0000BB">$reflection </span><span style="color: #007700">= new </span><span style="color: #0000BB">ReflectionFunction</span><span style="color: #007700">(</span><span style="color: #DD0000">'fruitBasket'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$parameter </span><span style="color: #007700">= </span><span style="color: #0000BB">$reflection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getParameters</span><span style="color: #007700">()[</span><span style="color: #0000BB">0</span><span style="color: #007700">];<br /></span><span style="color: #0000BB">$attributes </span><span style="color: #007700">= </span><span style="color: #0000BB">$parameter</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getAttributes</span><span style="color: #007700">(</span><span style="color: #DD0000">'Color'</span><span style="color: #007700">, </span><span style="color: #0000BB">ReflectionAttribute</span><span style="color: #007700">::</span><span style="color: #0000BB">IS_INSTANCEOF</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">array_map</span><span style="color: #007700">(fn(</span><span style="color: #0000BB">$attribute</span><span style="color: #007700">) =&gt; </span><span style="color: #0000BB">$attribute</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getName</span><span style="color: #007700">(), </span><span style="color: #0000BB">$attributes</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
     <div class="annotation-interactive examplescode"><pre class="examplescode">Array
(
    [0] =&gt; Red
)</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-reflectionparameter.getattributes-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="reflectionclass.getattributes.php" class="methodname" rel="rdfs-seeAlso">ReflectionClass::getAttributes()</a> - Gets Attributes</span></li>
    <li><span class="methodname"><a href="reflectionclassconstant.getattributes.php" class="methodname" rel="rdfs-seeAlso">ReflectionClassConstant::getAttributes()</a> - Gets Attributes</span></li>
    <li><span class="methodname"><a href="reflectionfunctionabstract.getattributes.php" class="methodname" rel="rdfs-seeAlso">ReflectionFunctionAbstract::getAttributes()</a> - Gets Attributes</span></li>
    <li><span class="methodname"><a href="reflectionproperty.getattributes.php" class="methodname" rel="rdfs-seeAlso">ReflectionProperty::getAttributes()</a> - Gets Attributes</span></li>
   </ul>
  </p>
 </div>


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