When not to close a php file?

前端 未结 3 1992
南笙
南笙 2021-01-11 21:11

I\'ve come across a tutorial (reputable one if I may add) where the closing php tag ?> was omitted. This reminded me of a previous tutorial where the author

3条回答
  •  囚心锁ツ
    2021-01-11 21:47

    Well, if you have an include file like config.php and you do not want it to output any characters because it's not meant to or you don't want to trigger "headers already sent" you can leave the closing tag off to make sure no whitespace is sent to the browser. You will find that files that are pure PHP and do not contain any content to be outputted, will generally not include a closing tag.

    The bottom line is you don't want to prematurly inject content before any headers are set. This is talked about in depth here.

提交回复
热议问题