I would leave this to personal preference, whether there is a closing ?> or
not wouldn't bother me. I could argue both ways:

Pro: You should put a final ?> for neatness and XML compatibility.
Con: It makes the script fractionally slower because 2 more characters have
to be processed and there might be issues with the header when it's already
sent. I've had that problem before and it's really annoying.

++Tim Hinnerk Heuer++


2010/1/9 Mattias Thorslund <matt...@thorslund.us>

> Hadn't paid much attention to the issue until reading a previous discussion
> on the topic, here on this list. After that, I decided to be consistent and
> leave the closing ?> out in all include files.
> To my eyes, ?> means "look there is more content coming", which seems kind
> of silly when there isn't.
> A neat thing with pairing every <?php with a ?> when mixed in HTML is that
> these are valid XML processing instructions. If your HTML satisfies XML
> well-formedness, your PHP document will also be valid XML. Not that I've
> ever had any need to process my layout templates as XML but anyway.
> Cheers,
> Mattias
> Daevid Vincent wrote:
>> I'm having a debate with a co-worker about adding the final ?> on a PHP
>> page...
>> To be honest, I am the lead, and I could pull rank and be done with the
>> discussion, however I don't like to be that way. I would rather do the
>> right thing. If my way of thinking is old-school (I've been coding since
>> PHP/FI), and what he says is the newfangled proper PHP/Zend way, then I'd
>> rather adopt that, despite how icky it makes me feel to leave an unclosed
>> <?php just dangling and alone, all sad-like. In my mind, "nobody gets left
>> behind"! :)
>> Is there ANY side-effects to leaving the end ?> off? Is it any more work
>> for the compiler? And yes I know computers are hella-fast and all that,
>> but
>> I come from the gaming industry where squeeking out an extra FPS matters,
>> and shaving off 0.01s per row of data in a table matters if you have more
>> than 100 rows. A 1 second wait IS noticeable and a 10 second is even
>> moreso
>> -- just try to talk for 10 seconds straight without a pause. Or sit there
>> and stare at a screen for 10 seconds!
>> If the main argument is that it's to prevent white-space after the code,
>> then most modern editors that I'm aware of will automatically trim
>> white-space (or have a setting to do so). Plus this is ONLY a factor when
>> you're trying to output a header and things like that. In 90% of your
>> code,
>> you don't deal with that. It's also obvious enough when you have an extra
>> character/space because PHP pukes on the screen and TELLS you something
>> about "blah blah sent before header output" or something to that effect.
>> What do you guys all do?
>> I also created a poll here http://www.rapidpoll.net/arc1opy
>> -----Original Message-----
>> From: Co-worker
>> To: Daevid Vincent
>> Actually, Zend states that you should omit the final ?> on include pages.
>> There is no harm in the action, and it prevents you from accidentally
>> adding white space after the tag which will break the code.
>> http://framework.zend.com/manual/en/coding-standard.php-file-formatting.htm
>> l
>> -----Original Message-----
>> From: Daevid Vincent To: Co-worker
>> Please DO include the final ?> I noticed on several of your files that you
>> have purposely omitted it. Yes, I know the files work without them, but it
>> makes things easier to see the pairings for matching <?php . Plus it keeps
>> things consistent and I'm not a big fan of "special cases" as this is,
>> especially if it's a bad habit to get into since in all other cases it's
>> required except this one "lazy" one. If you are concerned about white
>> space
>> sending in a header or something, well then just make sure there isn't
>> any.
>> I've had no problems and it makes you a more careful coder.
>> Thanks,
>> Daevid.
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to