What are common pitfalls to watch out for when using HEREDOC syntax in PHP code, and how can they be avoided?

One common pitfall when using HEREDOC syntax in PHP code is forgetting to properly terminate the closing identifier with a semicolon. This can lead to syntax errors or unexpected behavior in your script. To avoid this issue, always ensure that the closing identifier is terminated correctly.

// Incorrect usage of HEREDOC syntax
$heredoc = <<<EOD
This is a HEREDOC string
EOD // Missing semicolon

// Corrected HEREDOC syntax
$heredoc = <<<EOD
This is a HEREDOC string
EOD;