문제

How do I add this kind of function...

__("go") 

inside:

<<<_END

...without having to declare the variables before the heredoc? It's just too time consuming. I would like that my heredoc can read such functions __("go") without having to put them inside variables externally.

Thanks for your help.

도움이 되었습니까?

해결책

I suppose you could butcher magic methods for this:

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top