File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 18
18
expression, it would be expressed thusly:
19
19
<code >[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*</code >
20
20
</para >
21
+ <para >
22
+ It is possible to <function >define</function > constants with reserved or even
23
+ invalid names, whose value can (only) be retrieved with
24
+ <function >constant</function >. However, doing so is not recommended.
25
+ </para >
21
26
&tip.userlandnaming;
22
27
<para >
23
28
<example >
Original file line number Diff line number Diff line change 29
29
<para >
30
30
The name of the constant.
31
31
</para >
32
+ <note >
33
+ <para >
34
+ It is possible to <function >define</function > constants with reserved or
35
+ even invalid names, whose value can (only) be retrieved with
36
+ <function >constant</function >. However, doing so is not recommended.
37
+ </para >
38
+ </note >
32
39
</listitem >
33
40
</varlistentry >
34
41
<varlistentry >
@@ -139,6 +146,37 @@ echo ANIMALS[1]; // outputs "cat"
139
146
</programlisting >
140
147
</example >
141
148
</para >
149
+ <para >
150
+ <example >
151
+ <title >Constants with Reserved Names</title >
152
+ <para >
153
+ This example illustrates the <emphasis >possibility</emphasis > to define a
154
+ constant with the same name as a
155
+ <link linkend =" language.constants.predefined" >magic constant</link >.
156
+ Since the resulting behavior is obviously confusing, it is not recommended
157
+ to do this in practise, though.
158
+ </para >
159
+ <programlisting role =" php" >
160
+ <![CDATA[
161
+ <?php
162
+ var_dump(defined('__LINE__'));
163
+ var_dump(define('__LINE__', 'test'));
164
+ var_dump(constant('__LINE__'));
165
+ var_dump(__LINE__);
166
+ ?>
167
+ ]]>
168
+ </programlisting >
169
+ &example.outputs;
170
+ <screen >
171
+ <![CDATA[
172
+ bool(false)
173
+ bool(true)
174
+ string(4) "test"
175
+ int(5)
176
+ ]]>
177
+ </screen >
178
+ </example >
179
+ </para >
142
180
</refsect1 >
143
181
144
182
<refsect1 role =" seealso" >
You can’t perform that action at this time.
0 commit comments