Effect of omitting ?> ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Scrumpy.Gums
Forum Commoner
Posts: 71
Joined: Thu Aug 30, 2007 2:57 pm
Location: Bristol, UK

Effect of omitting ?> ?

Post 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)?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Effect of omitting ?> ?

Post 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.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: Effect of omitting ?> ?

Post 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.
Post Reply