Do you always close your <?php blocks?

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
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Do you always close your <?php blocks?

Post by nielsene »

So after posting some of my code for illustration purposes, hob_goblin pointed out that either the display was cut-off or the file was missing its close '?>'. Looking over my other files, I noticed that I almost never close the php blocks in my libraries/classes. I know that php automatically drops into html mode on a new file so this isn't a real problem.

I could make the arguement that it makes it easier to avoid a stray newline at the end of the file wrecking havoc with later headers.

Or am I just trying to justify laziness/sloppy coding :D?
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

lazy, sloppy, and frowned upon .. if you open a <?php end somewhere with a ?>
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

For some reason, when I forget to add my ?>, it quits with an error.
Image Image
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Have you got any HTML code after the place where you meant to have put the ?>?
conthox
Forum Commoner
Posts: 39
Joined: Tue Jun 25, 2002 1:44 pm
Location: Sweden

good thing to remember

Post by conthox »

A good thing to remember is to always do a end tag for your code, nomatter if it is a PHP or JavaScript or HTML or something else.

In the future, the XHTML and XML langugage maybe is the thing - and it demands stop-tags.
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Re: good thing to remember

Post by Takuma »

conthox wrote:A good thing to remember is to always do a end tag for your code, nomatter if it is a PHP or JavaScript or HTML or something else.

In the future, the XHTML and XML langugage maybe is the thing - and it demands stop-tags.
True True True.....
User avatar
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

Post by gotDNS »

I agree with conthox...it's always a good idea to end them...I mean, y not? Plus, be neat...so also, if u ever want to make changes later, u dont spend hours looking through confusing code to find somethings...

Be a neat freak...be smiled upon.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

OK I've been a good boy and closed all those missing tags on my dev tree. I hadn't thought of considering it in an xml context, probably because all my files are simply bracketed in the php tags, without switching in and out of html/php mode. Thanks for all the comments.
Post Reply