doupu2722 2013-08-04 12:39
浏览 39

HEREDOC中的静态函数调用结果

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?

  • 写回答

1条回答 默认 最新

  • dqch34769 2013-08-04 16:04
    关注

    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);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作