Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I close my PHP tags? [duplicate]

Tags:

php

Possible Duplicate:
Why do some scripts omit the closing PHP tag, '?>'?

I've seen in a PHP framework (I can't remember which) that they didn't close the php tag (?>) at the bottom of the pages.

Why is that and should I do it too?

like image 655
gion_13 Avatar asked Apr 18 '11 10:04

gion_13


2 Answers

If it's a PHP file that contains no HTML, then don't close the tag.

This stops you from accidentally adding whitespace at the end of the file, therefore invoking browser output, and by extension headers, etc, which can cause a world of pain.

like image 93
Stephen Melrose Avatar answered Oct 14 '22 21:10

Stephen Melrose


The framework you saw is most probably Zend Framework. From the code style section of their manual:

For files that contain only PHP code, the closing tag ("?>") is never permitted. It is not required by PHP, and omitting it´ prevents the accidental injection of trailing white space into the response.

like image 30
Treffynnon Avatar answered Oct 14 '22 21:10

Treffynnon