I was surprised to see that the following doesn't work as expected.
define('CONST_TEST','Some string');
echo "What is the value of {CONST_TEST} going to be?";
outputs: What is the value of {CONST_TEST} going to be?
Is there a way to resolve constants within curly braces?
Yes, I am aware I could just do
echo "What is the value of ".CONST_TEST." going to be?";
but I'd prefer not to concatanate strings, not so much for performance but for readability.
Nope that's not possible because php will consider CONST_TEST
to be a mere string inside the single/double quotes. You will have to use the concatenation for that.
echo "What is the value of ".CONST_TEST." going to be?";
i don't understand why you have to make a big fuss out of it but you can always do:
define('CONST_TEST','Some string');
$def=CONST_TEST;
echo "What is the value of $def going to be?";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With