I'm using PHP 7.2.6
I've tried following program :
<?php
class beers {
const softdrink = 'rootbeer';
}
$rootbeer = 'A & W';
echo "I'd like an {${beers::softdrink}}\n"; //Output : I'd like an A & W
echo "I'd like an {beers::softdrink}\n"; //Output : I'd like an {beers::softdrink}
?>
In the above statement, in first echo statement value of the class constant softdrink
is evaluated as the string 'rootbeer' which in turn a variable name which contains the string 'A & W'. The value 'A & W' gets printed.
In second echo statement I only want to show the value present in the class constant softdrink
which is the string 'rootbeer'.
But I'm not able to do it. Please help me in this regard.
P.S. : Please don't ask me to achieve the output using string concatenation. I want to achieve the output only by using the class constant within a double quotes string.