Jump to content

Does a PHP script require "?>"


liderbug

Recommended Posts

I've just downloaded a 3d party app and I'm finding that most (98%) of the [files].php have a "<?php" but not a "?>" in them.  I created a tst.php...HW and it seems to not care.  An improvement? Mox-Nix? Poor form? Or the same coder the loves 0xEEE text on a 0xFFF background because it's sooooo cool.

 

Head @ 42 deg /////

 

Thanks

cal

 

 

Link to comment
Share on other sites

No, it is not required. There are good reasons to leave it off - such as the dreaded "Headers already sent error". As you may know, some commands will fail if any content has already been generated for display in the browser - such as a header() command. If you include multiple files into a script that *may* use a header() command later you cannot have any of those include files generate output if you will later invoke the header() function.

 

If you do use "?>" then you cannot have any characters following the closing tag. Else, it will be considered output for the browser. By leaving the "?>" off, then all of the content of the file is considered PHP code.

Link to comment
Share on other sites

From the manual

http://php.net/manual/en/language.basic-syntax.phptags.php

 

 

If a file is pure PHP code, it is preferable to omit the PHP closing tag at the end of the file. This prevents accidental whitespace or new lines being added after the PHP closing tag, which may cause unwanted effects because PHP will start output buffering when there is no intention from the programmer to send any output at that point in the script.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.