As a rule, I always add a closing tag, because this is the only time during the day that my question mark gets an exercise with a finger. This bad question mark doesn't get love in PHP; -)
But seriously, adding a closing tag when not needed can lead to really confusing errors. Because of this, I pulled out my hair all day. The problem usually is that after the closing tag there are spaces that you cannot easily see, but they are interpreted as part of the response body. This is bad news if you include this file in another script that wants to send a custom header later. You cannot send header information after the script starts sending the response body, so these small invisible spaces lead to a script error.
source share