leaving ?> off the end of a php file
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Considering I have only had one error in the several thousand scripts I've written that was created by some extraneous text after a closing tag gives me little reason to switch. .. And that error was in my first set of scripts.
Shouldn't we write our scripts properly and use headers_sent() anyways? Just like shouldn't we write our scripts to work without register_globals, be prepared for magic_quotes being on and off, properly handle errors instead of hiding them with "@," short tags being off, and all the other things in the "best practice" category we've built through all the work this community has done?
Shouldn't we write our scripts properly and use headers_sent() anyways? Just like shouldn't we write our scripts to work without register_globals, be prepared for magic_quotes being on and off, properly handle errors instead of hiding them with "@," short tags being off, and all the other things in the "best practice" category we've built through all the work this community has done?
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
Instead of all of them, I'll just respond to what was directed towards me.
Thing is, I've never (yes, you read that correctly) had a bug related to closing php tags (and introducing unwanted output).ole wrote:And the fact that is could introduce a bug into your code stands for nothing?That's all the reason I need....it doesn't look complete to me..
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
All arguments either way do not change the fact that it was recently confirmed by Zend that the closing '?>' at the end of a file when there is no further output -- is optional and that they have chosen to not use it. That's just information to use as you see fit.
For me, it is of no consequence and is what I consider part of the range of exciting coding standards topics I file under "the art of programming".
For me, it is of no consequence and is what I consider part of the range of exciting coding standards topics I file under "the art of programming".
Last edited by Christopher on Thu Aug 31, 2006 1:34 am, edited 2 times in total.
(#10850)
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
That's really not the point. Closing braces or parens or brackets is not optional -- you get an error. The fact that the ?> is optional if there is PHP code to the EOF is a feature of the language. No programmer's preference will change that fact and it is simply another bit of trivium we know about PHP to use as we see fit.Everah wrote:To me it just makes sense. If you open a { you close it, if you open a ( you close it. If you open a [ you close it. Logically, if you open a <?php you close it ?>.
(#10850)
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Well its obvious to me that I'm never going to changes some people's opinions here. Everyone seems to be justifing their current behaviour with the fact that the error is insignificant so I'll accept that.
Something like "Files with exclusively PHP" so basically class files yep.they only recommended doing that in class files.
headers_sent won't unsend the headers that are already sent, if you need to send headers and you can't there's a problem.Shouldn't we write our scripts properly and use headers_sent() anyways?
You guys must have great memories to be so sure of that.Thing is, I've never (yes, you read that correctly) had a bug related to closing php tags (and introducing unwanted output).Considering I have only had one error in the several thousand scripts
So? Attention to detail, my friend.It is only two characters
Are you worried that if you stop closing <?php you might start forgetting to close other things? Besides you're not stopping using ?> altogether.To me it just makes sense. If you open a { you close it, if you open a ( you close it. If you open a [ you close it. Logically, if you open a <?php you close it ?>.
And when that happens I would likely have to remove the ?> (not after looking through the whole file for echo, and all the functions that might print something) so it would be nice if it was never there in the first place.as PHP will tell you what line and file sent the headers
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Maybe that is the thing for me... I am not stopping use of the closing tag altogether. So it would be used here but not here. That, to me, just seems inconsistent. I know it it not required (so maybe my last post was not in the proper context) and I know it is only my preference (so no, you are not going to change my mind aboutole wrote:Are you worried that if you stop closing <?php you might start forgetting to close other things? Besides you're not stopping using ?> altogether.To me it just makes sense. If you open a { you close it, if you open a ( you close it. If you open a [ you close it. Logically, if you open a <?php you close it ?>.
This is just my opinion, logical or not.
Last edited by RobertGonzalez on Thu Aug 31, 2006 11:31 am, edited 1 time in total.
I've had this error due to copying a snippet from this forum. There was a space at the end which caused a header already sent error. Very easy to diagnose and fix.
As for me, doesn't matter. I do always use them. But I have noticed occasions where i've worked on an intense function and forgot the closing tag. The script still ran perfectly fine, which I thought was odd for a while.
So, in conclusion, I don't care.
As for me, doesn't matter. I do always use them. But I have noticed occasions where i've worked on an intense function and forgot the closing tag. The script still ran perfectly fine, which I thought was odd for a while.
So, in conclusion, I don't care.
Last edited by s.dot on Thu Aug 31, 2006 10:35 am, edited 1 time in total.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.