Do i need to close
I've seen in a PHP framework (I can't remember which) that they didn't close the Why is that and should I do it too?
asked Apr 18, 2011 at 10:46
1 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. answered Apr 18, 2011 at 10:49
Stephen MelroseStephen Melrose 4,6825 gold badges27 silver badges41 bronze badges 0 The framework you saw is most probably Zend Framework. From the code style section of their manual:
answered Apr 18, 2011 at 10:50
TreffynnonTreffynnon 21k6 gold badges62 silver badges97 bronze badges 1 Basically it means a PHP file won't have trailing whitespace. If you include a file with trailing whitespace and try to set header() or cookies or stuff like that, then the trailing whitespace will cause a problem.
answered Apr 18, 2011 at 10:49
bumperboxbumperbox 10k6 gold badges42 silver badges65 bronze badges I personally prefer not to do it as it caused some unexpected troubles in the past. If you have white space(s) after closing tag, it might cause some troubles (like outputting this white space to browser, which is unpleasant if you are parsing XMLs) which are quite hard to debug. answered Apr 18, 2011 at 10:51
Ondrej SlintákOndrej Slinták 30.7k20 gold badges92 silver badges125 bronze badges You don't have to, as long as it's also the end of that script. Adding answered Apr 18, 2011 at 10:49
Adam HopkinsonAdam Hopkinson 27.7k7 gold badges65 silver badges95 bronze badges anisgazig at gmail dot com ¶ 10 months ago
|