reference/misc/functions/constant.xml
6c3091b54b66181db5f81ef5afe1d2e8b6efdeac
...
...
@@ -23,7 +23,8 @@
23
23
</simpara>
24
24
<simpara>
25
25
This function works also with <link
26
-
linkend="language.oop5.constants">class constants</link>.
26
+
linkend="language.oop5.constants">class constants</link> and <link
27
+
linkend="language.types.enumerations">enum cases</link>.
27
28
</simpara>
28
29
</refsect1>
29
30

...
...
@@ -53,9 +54,8 @@
53
54
<refsect1 role="errors">
54
55
&reftitle.errors;
55
56
<para>
56
-
An <classname>Error</classname> exception is thrown,
57
-
if the constant is not defined. Prior to PHP 8.0.0,
58
-
an <constant>E_WARNING</constant> level error was generated in that case.
57
+
If the constant is not defined, an <classname>Error</classname> exception is thrown.
58
+
Prior to PHP 8.0.0, an <constant>E_WARNING</constant> level error was generated in that case.
59
59
</para>
60
60
</refsect1>
61
61

...
...
@@ -87,7 +87,7 @@
87
87
&reftitle.examples;
88
88
<para>
89
89
<example>
90
-
<title><function>constant</function> example</title>
90
+
<title>Using <function>constant</function> with Constants</title>
91
91
<programlisting role="php">
92
92
<![CDATA[
93
93
<?php
...
...
@@ -115,6 +115,28 @@ var_dump(constant('foo::'. $const)); // string(7) "foobar!"
115
115
]]>
116
116
</programlisting>
117
117
</example>
118
+
<example>
119
+
<title>Using <function>constant</function> with Enum Cases (as of PHP 8.1.0)</title>
120
+
<programlisting role="php">
121
+
<![CDATA[
122
+
<?php
123
+

124
+
enum Suit
125
+
{
126
+
case Hearts;
127
+
case Diamonds;
128
+
case Clubs;
129
+
case Spades;
130
+
}
131
+

132
+
$case = 'Hearts';
133
+

134
+
var_dump(constant('Suit::'. $case)); // enum(Suit::Hearts)
135
+

136
+
?>
137
+
]]>
138
+
</programlisting>
139
+
</example>
118
140
</para>
119
141
</refsect1>
120
142

121
143