views:

49

answers:

3

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;
+4  A: 

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

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

Jacob Relkin
+4  A: 

Yes you can.

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

codaddict
Downvoer: care to explain ?
codaddict
+1  A: 

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.

mojuba