PHP static variables in double quotes
I don’t know the answer to your question, but you can show the class name and method using the __METHOD__
magic constant.
Sorry, you can't do that. It only works for simple expressions. See here.
Use an anonymous identity function stored in a variable. This way you will have $
immediately after {
:
$I = function($v) { return $v; };
$interpolated = "Doing {$I(self::FOO)} with {$I(self::BAR)}";
(I am using class constants in this example but this will work with static variables too).
Unfortunately there is no way how to do this yet. Example in one of answers here will not work, because {${self::$CLASS}}
will not returns content of self::$CLASS
, but will returns content of variable with name in self::$CLASS
.
Here is an example, which does not returns myvar
, but aaa
:
$myvar = 'aaa';
self::$CLASS = 'myvar';
echo "{${self::$CLASS}}";