From: Nitin R. <nit...@da...> - 2010-03-01 12:00:41
|
Hi! I've noticed that when creating Mantis plugins, leaving out the closing PHP tag (the "?>") is encouraged. I'm not really sure why, but the Joomla community recommends it too. Why is this practice followed? I'm guessing this might be to ensure no spaces are sent to the output stream before sending out headers, seeing how many PHP developers accidentally add in a blank line or space following the closing PHP tag. Also, I've noticed that the examples in the Mantis plugin overview examples declare arrays with a comma following the last element, like this: array(1, 2, 3, ) Is there any reason why we add in the extra comma? -Nitin |
From: John R. <jr...@le...> - 2010-03-01 14:19:41
|
Nitin Reddy wrote: > Hi! > > I've noticed that when creating Mantis plugins, leaving out the closing > PHP tag (the "?>") is encouraged. I'm not really sure why, but the > Joomla community recommends it too. Why is this practice followed? I'm > guessing this might be to ensure no spaces are sent to the output stream > before sending out headers, seeing how many PHP developers accidentally > add in a blank line or space following the closing PHP tag. That is more-or-less the correct reasoning. > Also, I've noticed that the examples in the Mantis plugin overview > examples declare arrays with a comma following the last element, like > this: array(1, 2, 3, ) > Is there any reason why we add in the extra comma? When creating multi-line array definitions, adding a comma after every element, including the last one, allows for patch diffing to look nicer. For example, if you leave out the last comma, and then want to add another item, the patch removes a line, and adds two. However, with the last comma, the same patch only adds a single line, which more closely represents the change made to the file. Basically, it's an aesthetic style designed to make the commit logs shorter and easier to understand. Cheers -- John Reese LeetCode.net |
From: nobs <no...@no...> - 2010-03-01 14:54:27
|
Am Montag 01 März 2010 12:57:51 schrieb Nitin Reddy: > I've noticed that when creating Mantis plugins, leaving out the closing PHP > tag (the "?>") is encouraged. I'm not really sure why, but the Joomla > community recommends it too. Why is this practice followed? I'm guessing > this might be to ensure no spaces are sent to the output stream before > sending out headers, seeing how many PHP developers accidentally add in a > blank line or space following the closing PHP tag. They are not needed syntactically and your guess is just the point. Any Character after the ?> including all whitespaces will be sent to the output. And that is most likely not what you want. Of course in most cases is just does not matter much. > Also, I've noticed that the examples in the Mantis plugin overview examples > declare arrays with a comma following the last element, like this: > array(1, 2, 3, ) Is there any reason why we add in the extra comma? This is syntactically allowed just for convinience in PHP. So you can list your array items line by line and if you add, remove or comment out an item it does not matter if it is the last one or not. You just add the separator. Both questions are not Mantis-related. They are just PHP knowledge. You can better discuss this en detail in a PHP forum. |