PHP supports this:
$z = 5;
$str = "z is $z"; // result: "z is 5"
and it supports this:
$c = new StdClass();
$c->x = 9;
$str = "x is {$c->x}"; // result: "x is 9"
but it does NOT support this:
class abc
{
const n = 2;
}
$str = "x is {abc::n}"; // result: "x is {abc::n}"
Why does PHP not support insertion of consts via the curly-brace syntax? Seems like it should…
The curly syntax is the extended variable syntax. It is used to interpolate variables into strings. And as in PHP variables start with
$everything else will yield a syntax error.But what you can do is call variable-functions. Thus you could do:
But that’s a hack which normally isn’t appropriate. Instead please use string concatenation: