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 1818 expression, it would be expressed thusly:
1919 <code >[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*</code >
2020 </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 >
2126 &tip.userlandnaming;
2227 <para >
2328 <example >
Original file line number Diff line number Diff line change 2929 <para >
3030 The name of the constant.
3131 </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 >
3239 </listitem >
3340 </varlistentry >
3441 <varlistentry >
@@ -139,6 +146,37 @@ echo ANIMALS[1]; // outputs "cat"
139146 </programlisting >
140147 </example >
141148 </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 >
142180 </refsect1 >
143181
144182 <refsect1 role =" seealso" >
You can’t perform that action at this time.
0 commit comments