Heredoc officially more fiddly than defusing an atomic bomb

Walked into this AGAIN today. Don’t put any whitespace after the closing heredoc identifier or you get stupid and inexplicable PHP errors, such as unexpected end


$html = <<< EOF
...lots of hypertexty goodness here
EOF;<--- any whitespace or tabs here will ruin your day

This is because the closing identifier it is looking for is actually


\nEOF\n

(with or without an optional semicolon)

Advertisements