note 92951 added to function.define

From: Date: Sun, 16 Aug 2009 00:54:50 +0000
Subject: note 92951 added to function.define
Groups: php.notes 
Request: Send a blank email to php-notes+get-159536@lists.php.net to get a copy of this message
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'); ?> ---- Server IP: 89.31.146.176 Probable Submitter: 82.225.170.198 ---- Manual Page -- http://www.php.net/manual/en/function.define.php Edit -- https://master.php.net/note/edit/92951 Del: integrated -- https://master.php.net/note/delete/92951/integrated Del: useless -- https://master.php.net/note/delete/92951/useless Del: bad code -- https://master.php.net/note/delete/92951/bad+code Del: spam -- https://master.php.net/note/delete/92951/spam Del: non-english -- https://master.php.net/note/delete/92951/non-english Del: in docs -- https://master.php.net/note/delete/92951/in+docs Del: other reasons-- https://master.php.net/note/delete/92951 Reject -- https://master.php.net/note/reject/92951 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159536) next »