note 92951 deleted from function.define by cmb
| From: | cmb@php.net | Date: | Sun, 06 Oct 2019 07:50:13 +0000 |
| Subject: | note 92951 deleted from function.define by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212471@lists.php.net to get a copy of this message | ||
Note Submitter: bohwaz.net
----
Note that define don't care at all about the constant name, you can give everything as a
constant name, even if the PHP documentation says that the allowed characters are
[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*
Just try this :
<?php define('anything::()$', 'test'); ?>
You won't be able to access this constant though, it will throw a parse error, either through
constant() or define(), but if you do that :
<?php print_r(get_defined_constants()); ?>
You will see that the constant is registered at the end of the array. Yes that's totally
useless. But you can try other things that will work with constant() :
<?php define('...', 'test'); echo constant('...'); ?>
Will echo 'test'. Yeah that's a pretty strange behavior.
And please note that defining object constants outside of objets don't work :
<?php
class myObject { }
define('myObject::CONSTANT', 'test');
?>