liderbug Posted November 17, 2014 Share Posted November 17, 2014 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 Quote Link to comment Share on other sites More sharing options...
Solution Psycho Posted November 17, 2014 Solution Share Posted November 17, 2014 (edited) 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. Edited November 17, 2014 by Psycho Quote Link to comment Share on other sites More sharing options...
liderbug Posted November 17, 2014 Author Share Posted November 17, 2014 Ah, thanks. Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 17, 2014 Share Posted November 17, 2014 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.