To close or not to close php

Yes, please avoid closing PHP tags at the end of the file, not only with PHP 7, but with PHP 5 as well.

Reason is that if you close the tag, anything that is after the tag, even a blank line, will be sent to output and will make PHP to send headers as well preventing cookie to be set, redirect to work, feed to be valid, and so on.

I guess that you ever encountered a message like

Cannot modify header information – headers already sent by (output started at …) in … on line …

A closing ?> at end of the file can be the cause.

Leave a Comment