Page 2 of 2

Posted: Wed Aug 30, 2006 9:29 pm
by feyd
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?

Posted: Wed Aug 30, 2006 9:34 pm
by d3ad1ysp0rk
Instead of all of them, I'll just respond to what was directed towards me.
ole wrote:
...it doesn't look complete to me..
That's all the reason I need.
And the fact that is could introduce a bug into your code stands for nothing?
Thing is, I've never (yes, you read that correctly) had a bug related to closing php tags (and introducing unwanted output).

Posted: Wed Aug 30, 2006 10:02 pm
by Christopher
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". ;)

Posted: Wed Aug 30, 2006 10:44 pm
by Charles256
here's a good reason for using ?> in my opinion. it gets you in practice of closing your php tags for those times your mixing HTML and PHP (spare me that war, just saying :-D ) :-D

Posted: Thu Aug 31, 2006 12:03 am
by RobertGonzalez
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 ?>.
  • It is only two characters
  • It visually delineates a script
  • It eliminates potential mixed code errors
  • It maintains tabbed structure

Posted: Thu Aug 31, 2006 1:42 am
by Christopher
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 ?>.
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.

Posted: Thu Aug 31, 2006 5:34 am
by Benjamin
Based on what I remember reading, and I could be wrong, they only recommended doing that in class files.

I don't know what the big deal is though, as PHP will tell you what line and file sent the headers.

Posted: Thu Aug 31, 2006 6:08 am
by Ollie Saunders
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.
they only recommended doing that in class files.
Something like "Files with exclusively PHP" so basically class files yep.
Shouldn't we write our scripts properly and use headers_sent() anyways?
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.
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
You guys must have great memories to be so sure of that.
It is only two characters
So? Attention to detail, my friend.
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 ?>.
Are you worried that if you stop closing <?php you might start forgetting to close other things? Besides you're not stopping using ?> altogether.
as PHP will tell you what line and file sent the headers
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.

Posted: Thu Aug 31, 2006 7:23 am
by volka
astions wrote:Based on what I remember reading, and I could be wrong,[...]
That's why would be nice to know the source ;)

Posted: Thu Aug 31, 2006 8:58 am
by RobertGonzalez
ole 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 ?>.
Are you worried that if you stop closing <?php you might start forgetting to close other things? Besides you're not stopping using ?> altogether.
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 about :) ), but it just seems logical to include it. It hurts nothing if developed properly and allows for consistent coding throughout a project.

This is just my opinion, logical or not.

Posted: Thu Aug 31, 2006 10:32 am
by s.dot
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. :oops:

Posted: Thu Aug 31, 2006 10:34 am
by Luke
yea I really don't care either. Not a big deal :? :roll: