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

...
...
@@ -46,24 +47,47 @@
46
47
<refsect1 role="returnvalues">
47
48
&reftitle.returnvalues;
48
49
<para>
49
-
Returns the value of the constant, or &null; if the constant is not
50
-
defined.
50
+
Returns the value of the constant.
51
51
</para>
52
52
</refsect1>
53
53

54
54
<refsect1 role="errors">
55
55
&reftitle.errors;
56
56
<para>
57
-
An <constant>E_WARNING</constant> level error is generated if the
58
-
constant is not defined.
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

62
+
<refsect1 role="changelog">
63
+
&reftitle.changelog;
64
+
<informaltable>
65
+
<tgroup cols="2">
66
+
<thead>
67
+
<row>
68
+
<entry>&Version;</entry>
69
+
<entry>&Description;</entry>
70
+
</row>
71
+
</thead>
72
+
<tbody>
73
+
<row>
74
+
<entry>8.0.0</entry>
75
+
<entry>
76
+
If the constant is not defined, <function>constant</function> now throws an
77
+
<classname>Error</classname> exception; previously an <constant>E_WARNING</constant>
78
+
was generated, and &null; was returned.
79
+
</entry>
80
+
</row>
81
+
</tbody>
82
+
</tgroup>
83
+
</informaltable>
84
+
</refsect1>
85
+

62
86
<refsect1 role="examples">
63
87
&reftitle.examples;
64
88
<para>
65
89
<example>
66
-
<title><function>constant</function> example</title>
90
+
<title>Using <function>constant</function> with Constants</title>
67
91
<programlisting role="php">
68
92
<![CDATA[
69
93
<?php
...
...
@@ -91,6 +115,28 @@ var_dump(constant('foo::'. $const)); // string(7) "foobar!"
91
115
]]>
92
116
</programlisting>
93
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>
94
140
</para>
95
141
</refsect1>
96
142

...
...
@@ -100,6 +146,7 @@ var_dump(constant('foo::'. $const)); // string(7) "foobar!"
100
146
<simplelist>
101
147
<member><function>define</function></member>
102
148
<member><function>defined</function></member>
149
+
<member><function>get_defined_constants</function></member>
103
150
<member>The section on <link linkend="language.constants">Constants</link></member>
104
151
</simplelist>
105
152
</para>
106
153