I just tried the following:
<?php
$script = <<<HEREDOC
var delUrl = '{ScriptManager::getDelUrl()}';
HEREDOC;
echo $script;
?>
And in the browser I get:
// Used by JS
var delUrl = '{ScriptManager::getDelUrl()}';
Instead of seeing the result of the static call ScriptManager::getDelUrl()
the output is the literal PHP. Is there a way to make static calls get evaluated inside HEREDOC, possibly without assigning their values to a variable before the HEREDOC?
I demo a static call, but on an object.
This must be done on a recent version of PHP, they recently made it more complex. The results of ln4 and ln5 are computed. Is it possible to have the object, not the class?
<?php
error_reporting(-1);
print("this is PHP".phpversion()."
");
$a=1;
class b {
public $c=3;
public static function d() {
return 4;
}
}
$e=new b();
$t=<<<EOSAMPLE
hwllo world $a
ln1 {b->$c}
ln3 {b::d()}
ln4 {$e::d()}
ln5 {$e->d()}
ln2 {$e->c}
EOSAMPLE;
print($t);
$t=<<<'EOSAMPLE'
hwllo world $a
ln1 {b->$c}
ln3 {b::d()}
ln4 {$e::d()}
ln5 {$e->d()}
ln2 {$e->c}
EOSAMPLE;
print($t);
$t=<<<"EOSAMPLE"
hwllo world $a
ln1 {b->$c}
ln3 {b::d()}
ln4 {$e::d()}
ln5 {$e->d()}
ln2 {$e->c}
EOSAMPLE;
print($t);