PHP Tip
Rafe Colburn: I didn’t know until just now that you don’t need to include the closing ?> in PHP files that consist entirely of code. The Drupal coding standards explain why you probably want to leave it out:
Note that the final ?> should be omitted from all code files–modules, includes, etc. The closing delimiter is optional, and removing it helps prevent unwanted white space at the end of files which can cause problems elsewhere in the system.
News to me too. This may also be the cause of a rather common feed error. I’ve added the recommendation to the front of the solution section in the hopes that it helps somebody.
Good catch. I added some more text to make this clearer. Let me know if you think it still needs to be tweaked a bit.
Posted by Sam Ruby at
I too just discovered this (thanks to a co-worker). More info in the PHP docs here:
Posted by Justin Watt at
Another way to solve the extra whitespace problem is to end your files like this:
return;
?>
The Zend Framework Coding Standard also forbids the use of PHP closing tags in code-only files.
It can makes files look a bit unbalanced (like unmatched parenthesis, and can make you wonder if the file has been truncated. But it certainly has practical benefits.
Posted by Paul Annesley atwill that cause the SVG icons to stop displaying at 1280x1024 for each one? g-d knows what havoc a trailing space or newline can wreak..
Posted by cr at
shared an item on Google Reader
PHP Tip 13 hours ago - Comment Huy Zing , Kevin Fox and Voyagerfan5761 liked this This is a good trick. I know for a fact that MediaWiki (one large PHP app) does this. - Voyagerfan5761 I did not know this, and have assiduously removed...Excerpt from Chris Wetherell - FriendFeed at
[from ianb] Sam Ruby: PHP Tip
For all you many PHPers reading this, a little coding style tip (though I don’t know if we should just stick with WP style, whatever the heck that is)...Excerpt from del.icio.us/network/huangyi at
As a note, having a single line break after the closing end tag is perfectly acceptable.
Posted by Ryan McCue at
shared an item on Google Reader
PHP Tip March 27 at 8:05 am - Comment John Mangino liked this Nice timing. This fixed a wall I had just hit last night. :-) Thanks! - John Mangino...Excerpt from Larry - FriendFeed at
I find the recommendation as written to be confusing: it’s not clear that the ?> you’re referring to there is a PHP ?> and not the ?> from <?xml ... ?>, which is the only obvious antecedent on the page.
Posted by David Glasser at