[ACCEPTED]-quoting constants in php: "this is a MY_CONSTANT-quoting
Sorry, that's not the way constants in PHP 2 work. You can put variables in double quotes 1 and heredocs but not constants.
I recomend you to use concatenation because:
- When you use a variable into a double quotes string your visibility is not good;
- When you use a double quotes string the php can to process slowly;
- You don't use a constant into a string, because don't have any delimiter to the php knows what is the constant.
0
Concatenation is the way to go.
Unless you 2 want the hokey, nasty, inefficient, evil 1 monkey way of:
echo preg_replace("/TESTER/",TESTER,$original_content);
Posting for anyone who might find it useful, something 6 like this will work:
<?php
// example code
define('AAA', '30V');
$constant = 'constant';
echo "{$constant('AAA')}"; //Echoes 30V
Trust me, neither I 5 believed something like this was possible, but 4 it is! Try it in tehplayground.com and see 3 for yourself.
Credit goes to whoever though 2 of it, and to my colleague who found it 1 (I think he did in stackoveflow).
no way, unless you write your own string 1 parsing function
I've found that when dot-concatenation of 3 a constant is a problem, using sprintf to 2 get my string is usually the way I want 1 to go in the end.
Alternatively, do
"this is " . MY_CONSTANT
or
"this is " . constant("MY_CONSTANT");
0
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.