php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #76316 fail to print newline after end tag in included file
Submitted: 2018-05-09 10:15 UTC Modified: 2018-05-09 12:37 UTC
From: divinity76 at gmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 7.2.5 OS: linux, debian 10 x64 k4.16.5-1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: divinity76 at gmail dot com
New email:
PHP Version: OS:

 

 [2018-05-09 10:15 UTC] divinity76 at gmail dot com
Description:
------------
reading the docs at http://php.net/manual/en/language.basic-syntax.phptags.php , >>>everything outside of a pair of opening and closing tags is ignored by the PHP parser. <<< everything outside of the closing tag should be ignored by the parser, and just printed, and further >>>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.<<<

here it's at least heavily implied that newlines after the end tag will be printed, but this is not actually the case. newlines after the end tags seems to be not printed, almost as if it was part of the end tag.

Test script:
---------------
<?php
$tmp=tmpfile();
fwrite($tmp,"<?php ?>\n");
ob_start();
require(stream_get_meta_data($tmp)['uri']);
var_dump(bin2hex(ob_get_clean()));

Expected result:
----------------
string(2) "0a"

Actual result:
--------------
string(0) ""

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-09 12:37 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2018-05-09 12:37 UTC] requinix@php.net
The next page says
> ...when the PHP interpreter hits the ?> closing tags, it simply starts outputting whatever it finds (except for an
> immediately following newline - see instruction separation)...
http://php.net/manual/en/language.basic-syntax.phpmode.php

And the page after that, which it linked to,
> The closing tag for the block will include the immediately trailing newline if one is present.
http://php.net/manual/en/language.basic-syntax.instruction-separation.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 14 10:01:33 2024 UTC