I have the following piece of code, which doesn't work:
<?php
class test{
public static $var = 'foo';
public static function printvar(){
echo "Var value is {self::$var}";
}
}
test::printvar();
?>
However this works:
<?php
class test{
public static $var = 'foo';
public static function printvar(){
echo "Var value is " . self::$var;
}
}
test::printvar();
?>
Question is, is there anyway I can access the static variables inside quotes from inside a static method?
By manual:
Functions, method calls, static class variables, and class constants inside {$} work since PHP 5. However, the value accessed will be interpreted as the name of a variable in the scope in which the string is defined. Using single curly braces ({}) will not work for accessing the return values of functions or methods or the values of class constants or static class variables.
Read more string ...