Is it possible to concatenate heredoc string in PHP..?

pnichols picture pnichols · Oct 22, 2010 · Viewed 8.3k times · Source

With normal PHP string you can do this:

$str = "Hello ";
$str .= "world";
$str .= "bla bla bla";
$str .= "bla bla bla...";

But can you do the same with heredoc string..?

$str = <<<EOD
Hello 
world
EOD;

$str .= <<<EOD
bla bla bla";
bla bla bla...";
EOD;

Answer

Jacob Relkin picture Jacob Relkin · Oct 22, 2010

Of course. Why wouldn't you be able to?

Heredocs evaluate to a string, so this is perfectly acceptable.