Trailing line at end of files

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Do you have trailing newlines on your files?

Yes
2
29%
No
5
71%
 
Total votes: 7

User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Trailing line at end of files

Post by Ambush Commander »

I'm curious. It seems like most Unix tools expect there to be a trailing newline at the end of files; I've always been careful to make sure ?> is the last data in a file so that I don't get the dreaded headers already sent warning.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

A trailing new-line after the ?> is fine, provided no other characters are between them.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

I was vaguely aware that is the case. Of course, if you have two lines...
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Ambush Commander wrote:I was vaguely aware that is the case. Of course, if you have two lines...
That extra newline would be something between the ?> and the allowed newline. :P
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I don't use ?> which seems to be the Zend approved thing to do.
(#10850)
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

::does a quick test::

I never realized that; how long has this been allowed?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I get the sense that is has always been the case. When the EOF is reached, PHP ends parsing whether in HTML or PHP mode. In class files, using no ?> is the Zend recommendation.
(#10850)
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

arborint wrote:I get the sense that is has always been the case. When the EOF is reached, PHP ends parsing whether in HTML or PHP mode. In class files, using no ?> is the Zend recommendation.
In Dreamweaver, leaving it out causes the whole file to be highlighted in yellow. I've no idea how to disable that. :x
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

superdezign wrote:In Dreamweaver, leaving it out causes the whole file to be highlighted in yellow. I've no idea how to disable that. :x
Stop using Dreamweaver. :twisted:
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

That would seem like such a waste of money... :(
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

superdezign wrote:That would seem like such a waste of money... :(
It was. :)
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

:lol:

Which do you suggest? I used to use one called PHP Editor, but didn't like it. Is there anything similar to Visual Studio? (where it shows you your class structures and such)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

superdezign wrote:Which do you suggest? I used to use one called PHP Editor, but didn't like it. Is there anything similar to Visual Studio? (where it shows you your class structures and such)
We're pushing pretty far out of subject with this line of discussion, so might I suggest you read through the novel that is our "editors" thread? :)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

On Topic: I never use ?> so I don't have to worry about whether or not there is anything after it.

Off Topic: Use Eclipse. Better yet, Use Eclipse in Linux. Quanta is great too. I'd do either.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Zend IDE automatically removes trailing newlines.

$Zend++
Post Reply