Re:Things You Probably Didn’t Know About PHP
by dutchflyboy on Tuesday January 12, 2010 @09:03AM
(#1047442)
That's one of the most irritating problems with PHP due to the impossibility to find the bug (well, it's a whitespace, it's not as if one could see it). On my server, including a file with a whitespace after the ?> actually made the server send the PHP source code as text, including the mysql passwords that were included in the file.
Re:Things You Probably Didn’t Know About PHP
by andrewvc on Tuesday January 12, 2010 @10:22AM
(#1047625)
Ouch, I generally try to put password files in directories not even in www_root, that way if the web server config gets messed up this stuff isn't even possible.
Re:Things You Probably Didn’t Know About PHP
by ErrantX on Tuesday January 12, 2010 @09:05AM
(#1047446)
Most PHP dev's omit the closing tag anyway for a variety of reasons (mostly because, well, it's not needed)
Re:Things You Probably Didn’t Know About PHP
by raffi on Tuesday January 12, 2010 @09:07AM
(#1047454)
To a non-PHP programmer it's pretty non-intuitive to omit a closing tag. Most programmers are trained to balance things like tags, parentheses, and curly braces.
Re:Things You Probably Didn’t Know About PHP
by rbanffy on Tuesday January 12, 2010 @09:31AM
(#1047512)
"non-intuitive"? I would say "horrific", "disgusting" or something on these lines.
Re:Things You Probably Didn’t Know About PHP
by ErrantX on Tuesday January 12, 2010 @09:58AM
(#1047577)
I sort of agree; though I find the opening tag requirement to be the crazy one :) (though I see the reasoning).
Disgusting is a bit strong though ;)
Re:Things You Probably Didn’t Know About PHP
by bendtheblock on Tuesday January 12, 2010 @09:01AM
(#1047435)
The same occurs in Drupal template files (which are powered by PHPtemplate, by default anyway). Including the closing tag with whitespace after causes a white screen of death which can be infuriating to debug - unless you know this.
Re:Things You Probably Didn’t Know About PHP
by randallsquared on Tuesday January 12, 2010 @09:03AM
(#1047440)
The best way to handle this is not to even put a closing ?> unless you intend to have non-PHP in the file.
If you include a file with their include() function and have whitespace after the closing ?> tag in the file--PHP will throw an error.
Except it gets better: whether this happens or not depends on a setting in php.ini (output buffering I think).
This happens if you're trying to send header information from the parent file but include a file that outputs whitespace on accident. The output buffering delays sending the output (because it's buffered, duh :)) so the header info can be sent, hence no error.
This is one of those things I didn't know and wish I did.
http://stackoverflow.com/questions/1793482/php-error-cannot-...
The work around: omit the closing ?> tag from included files.