File tree Expand file tree Collapse file tree
reference/reflection/reflectionconstant Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments