php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #47707 Swallowing a newline immediately following a closing tag is a poor idea
Submitted: 2009-03-18 18:12 UTC Modified: 2009-03-26 14:52 UTC
From: diepiapaopolopo at hotmail dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.9 OS: All
Private report: No CVE-ID: None
 [2009-03-18 18:12 UTC] diepiapaopolopo at hotmail dot com
Description:
------------
Can the decision to call bugs #13954 and #21891 bogus be revisited, please?

Reproduce code:
---------------
<?
$quality="red";
?>
<p>Your apple is more <?=$quality?>
than mine.</p>

Expected result:
----------------
Your apple is more red than mine.

Actual result:
--------------
Your apple is more redthan mine.


Even though the behavior is documented (http://www.php.net/manual/en/language.basic-syntax.instruction-separation.php), swallowing a newline that immediately follows a closing tag seems to be a pretty poor idea, especially if the rationale is to pretty up formatting as is alluded to (http://bugs.php.net/bug.php?id=13954) by jeroen.

Swallowing the newline is a surprise to anyone who encounters this bug (yes, bug). Additionally, it can easily lead to malformatted output (see sample included in this report). This malformatting can be difficult to detect and the solution--adding a trailing space after every closing tag (seriously???)--is a kludge through and through. This malformatting becomes catastrophic if you're using PHP to generate input to another program, as is the case for many of the people that have discussed the issue over the years.

I realize this discussion has been going on for nearly a decade. I have to assume this topic has become largely a political discussion, rather than a problem solving one, because the problem hasn't been solved yet.

In the spirit of problem solving, several people have suggested adding a setting to php.ini to re-enable the current behavior, which should eliminate the need to refactor any scripts affected by the correction. In any case, the current behavior should not be the default behavior.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-22 16:40 UTC] johannes@php.net
Not doing this might have unwanted effects in other cases - consider a file starting with a PHP block and then some raw output.

We won't change this.
 [2009-03-26 14:52 UTC] diepiapaopolopo at hotmail dot com
Please consider the option of an ini setting (collapse_tag_whitespace=yes|no|longtag) to enable the current behavior. While the example you give is obviously going to happen occasionally, it is certainly less likely than a user intending for everything outside the PHP tags to remain intact. Even if the default behavior is still to collapse the newline after the tag, having an ini option to not collapse would be much better than the current work around (putting a space or an additional newline after the closing tag).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 01 20:01:29 2024 UTC