php - 定界符和特殊字符串

标签 php heredoc

如何添加这种功能...

__("go") 

内部:

<<<_END

...无需在定界符之前声明变量? 实在是太费时间了。 我希望我的heredoc可以读取这样的函数 __("go")无需将它们放入外部变量中。

感谢您的帮助。

最佳答案

我想你可以为此屠宰魔法方法:

class Magic
{
    public function __call($method, $args) {
        // would seriously recommend checking whether `$method` exists :)
        return call_user_func_array($method, $args);
    }
}

$magic = new Magic;

$str = <<<EOM
Hello this should give the {$magic->time()}.
EOM;

关于php - 定界符和特殊字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17109639/

相关文章:

ruby - Visual Studio Code 使用 HEREDOC 和单引号中断突出显示

Java 命令行输入与heredoc

bash - 使用存储在变量中的 HereDocument 的流程替换

php - 在动态情况下将按钮分配给相应的图像

php - Genesis 子主题的自定义帖子类型分页

javascript - 单击一个按钮对 jQuery 中的表格进行排序

javascript - 当用户单击第 1 页上的按钮时,它会将数据发送到第 2 页并重定向到第 3 页

PHP 计数 JSON 数组

bash - 嵌套的 EOF

ruby - Ruby 的 EOB 构造的用例