Tip: Don’t close your PHP tags

Adding a closing ?> to your <?php tags is actually optional, and you should avoid using it for scripts that will only be included.

I know a lot of you might be groaning and thinking “Just because you can, doesn’t mean you should”. We should always close our HTML tags and other things to avoid quirks, but this is actually quite different. PHP doesn’t require or desire that you close them. However, the small savings you’ll get from not closing them isn’t the reason you should be avoiding them.

Closing them can cause you to accidentaly leave a whitespace or new-line character at the end of your scripts. These characters will cause the HTTP headers to be sent to the browser, which will make some other functions (such as session_start()) that modify these headers to fail.

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

No Comments

Post a Comment

Your email is never shared. Required fields are marked *