Unexpected $end in PHP while using Heredoc syntax

Hello all of you.

You might be getting this error in case if you are using Heredoc syntax in your PHP program. First of all you need to know the fact that Heredoc syntax is very strict about it’s use. Always follow the syntax rule while programming in PHP.

The error “Unexpected $end on line xx” is mainly cause if you have white space after the closing Heredoc tag. As a reference please see the image below, in this image the green portion represents whitespace after closing EOD.

heredoc $end error

Delete this whitespace and error will be removed. Smile

Written by Neon, UB7 community member