Pregunta

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.

¿Fue útil?

Solución

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;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top