I experimented with this and I think that I can make an educated guess.
In the double quoted string section you have 3 newlines: one from line 2 to line 3, one from line 3 to line 4, and one from line 4 to line 5.
In the heredoc section you only have one newline. I think that the heredoc section starts on the line AFTER the first EOD token and ends on the line BEFORE the last EOD token. So in your heredoc you only have one newline from line 7 to 8 and you can see that in your output (the newline between the <
and the >
at the end). If you add more newlines to the heredoc section then you will see them in your output.
Hopefully this will help illustrate:
<?php
echo "dc:<"." <-- first newline
<-- second newline
<-- third newline
".">";
echo "hd:<".<<<EOD <-- heredoc starts after this part
<-- only one newline here
<-- heredoc ends here so this newline doesn't count
EOD
.">";
In response to your comments:
"In the heredoc section you only have one newline." I have three
Yes, but as I have said, I think that the first and last newlines are ignored.
"I think that the heredoc section starts on the line AFTER the first
EOD token and ends on the line BEFORE the last EOD token" No. See the
doc quote I posted.
Look at this text from the doc that you linked to (emphasis mine):
A third way to delimit strings is the heredoc syntax: <<<. After this
operator, an identifier is provided, then a newline. The string itself
follows, and then the same identifier again to close the quotation.
Notice that it says that the string itself follows the newline. I believe that this proves my assertion that first newline is omitted as it is part of the heredoc construct. Admittedly this only explains the first newline. But I believe that the last newline is ignored for the same reason.
"If you add more newlines to the heredoc section then you will see
them in your output." Yup, but still my output has the wrong quantity
of newlines.
That quote being: "Heredoc text behaves just like a double-quoted
string, without the double quotes."
I think that if your double quoted string section was structured like this...
<?php
echo 'dc:<'.
"
"
.'>';
echo "hd:<".<<<EOD
EOD
.">";
Then it would work like you expect. In other words, the heredoc works the same as double quoted string without the double quotes. Try it.