Page 1 of 1

Effect of omitting ?> ?

Posted: Fri Jun 06, 2008 5:23 am
by Scrumpy.Gums
A couple of times, I've seen the last close tag ?> being left off of a php script. What effect does this have (providing that there's no following code)?

Re: Effect of omitting ?> ?

Posted: Fri Jun 06, 2008 5:43 am
by onion2k
It means any whitespace after the closing tag that would break your headers (eg causing a "Headers already sent" error) won't ever be able to break your code again.

In theory it also makes PHP parse the script faster because it doesn't have to check if there's any more PHP after the closing tag. I've never bothered to benchmark it though so that might not actually be true.

For the record, I never put ?> at the end of my code these days.

Re: Effect of omitting ?> ?

Posted: Fri Jun 06, 2008 6:58 am
by Kieran Huggins
same here, another useful trick I learned here at DevNet :-)

There's really no reason to use it unless you have content after your code, in which case you should probably be using templates.... but I digress.