Why do these Heredoc and Nowdoc cause errors?

You probably have spaces after the terminator in your first two examples, e.g.

EOD;[space]

With this:

<?php
echo <<<EOL
test
EOL;[space]

I get your error message, but WITHOUT the space, there's no error. And that's true whether there's a closing ?> or not.


The closing delimiter must start on the first column, no spaces nor tabs allowed in front of it. Be aware that things are changing in 5.5 and 5.6

'EOD' is equivalent to echo ' ',
"EOD" is equivalent to echo " " about variable substitutions.

The closing delimiter doesn't take any single of double quotes.


Heredoc is very finicky. Make sure there are no spaces after your initial EOD. And the final EOD; must be on it's own line, with no spaces before it, and nothing else on that line. It's those spaces that give most people trouble.

And the quotes around 'EOD' aren't necessary.