Skip to content

Commit c3ad745

Browse files
committed
Add usage example to ReflectionConstant::getAttributes
1 parent ce513a1 commit c3ad745

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

reference/reflection/reflectionconstant/getattributes.xml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,46 @@
5757
</para>
5858
</refsect1>
5959

60+
<refsect1 role="examples">
61+
&reftitle.examples;
62+
<para>
63+
<example>
64+
<title>Basic usage</title>
65+
<programlisting role="php">
66+
<![CDATA[
67+
<?php
68+
#[Attribute]
69+
class Fruit {
70+
}
71+
72+
#[Attribute]
73+
class Red {
74+
}
75+
76+
#[Fruit]
77+
#[Red]
78+
const APPLE = 'apple';
79+
80+
$constant = new ReflectionConstant('APPLE');
81+
$attributes = $constant->getAttributes();
82+
print_r(array_map(fn($attribute) => $attribute->getName(), $attributes));
83+
?>
84+
]]>
85+
</programlisting>
86+
&example.outputs;
87+
<screen>
88+
<![CDATA[
89+
Array
90+
(
91+
[0] => Fruit
92+
[1] => Red
93+
)
94+
]]>
95+
</screen>
96+
</example>
97+
</para>
98+
</refsect1>
99+
60100
<refsect1 role="seealso">
61101
&reftitle.seealso;
62102
<simplelist>

0 commit comments

Comments
 (0)