Static string parsing in PHP

Pretty simple; I read the docs, but maybe I'm just a little confused by the explanation.

class Test{
    public static $var = 'world';
}

echo "hello {Test::$var}"; // only parses $var in current scope, which is empty

Is there any way to get the desired functionality here? I'm starting to guess, no, because I tried several permutations without success.

Explanation: I am trying to achieve this by parsing PHP variables, not concatenation. Obviously, I will resort to concatenation if the desired method is not possible, although I hope so.

+5
source share
3 answers

PHP " ". {$. {T , PHP $ Test::

-. NOP:

$html = "htmlentities";
print "Hello {$html(Test::$var)}";

:

$Test = "Test";
print "Hello {$Test::$var}";

, .

+8

.

class Test{
    public static $var = 'world';
}

echo "hello ", Test::$var;
0

(.)

echo "hello ".Test::$var; 

Note: functions, method calls, class static variables and class constants inside {$} work with PHP 5. However, the available value will be interpreted as the name of the variable in the area in which the string is defined. Using single curly braces ({}) will not work for accessing the return values ​​of functions or methods or values ​​of class constants or static class variables.

Source Via This Answer

0
source

All Articles