Question

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;
Was it helpful?

Solution

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

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

OTHER TIPS

Yes you can. Heredoc is part of expressions, so you can even do this:

$s = 'abc' . <<<EOD
def
EOD
. 'ghi';

Be careful with the end-of-data marker though: it should be the only thing on a line.

Yes you can.

A heredoc is equivalent to double quoted string without the double quotes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top