note 84411 added to language.constants
| From: | seth36 at gmail dot com | Date: | Sun, 13 Jul 2008 10:12:39 +0000 |
| Subject: | note 84411 added to language.constants | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-141445@lists.php.net to get a copy of this message | ||
Reply to ian at willis dot org dot uk
From the second line of the Syntax section above:
"Only scalar data (boolean, integer, float and string) can be contained in constants. Do not
define resource constants."
So the 'ccc' value of your constant would be interpreted by php as the string
'ccc', not a reference to the function. Furthermore the cfunc(); call that triggers the
error, as far as PHP is concerned, is just a normal function, since constants have no $ prefix, if
you used a constant as a reference to a function, how would PHP know what should be handled as a
regular function call and what should be handled as a constant function reference as the syntax
becomes the same.
You can create a variable from the value of the constant using ${CFUNC} so to create a reference to
the function from the constant you might be able to do:
<?php
define("CFUNC", "ccc");
${CFUNC}();
?>
I haven't tested this though and in all honesty I can't think why you'd even want to
use a constant as a function reference anyway for variable variables it make's sense,
particularly when you might not know the function name beforehand. A constant is as it's name
implies - it's constant, since it's value doesn't change it has no benefit as a
function reference as far as i can see since you must already know the function name (that you set
as the value of the constant) in order to create this constant reference, why not just call the
function directly?
----
Server IP: 92.48.74.199
Probable Submitter: 84.70.170.214
----
Manual Page -- http://www.php.net/manual/en/language.constants.php
Edit -- https://master.php.net/note/edit/84411
Del: integrated -- https://master.php.net/note/delete/84411/integrated
Del: useless -- https://master.php.net/note/delete/84411/useless
Del: bad code -- https://master.php.net/note/delete/84411/bad+code
Del: spam -- https://master.php.net/note/delete/84411/spam
Del: non-english -- https://master.php.net/note/delete/84411/non-english
Del: in docs -- https://master.php.net/note/delete/84411/in+docs
Del: other reasons-- https://master.php.net/note/delete/84411
Reject -- https://master.php.net/note/reject/84411
Search -- https://master.php.net/manage/user-notes.php