|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76439 Changed behaviour in unclosed HereDoc
Submitted: 2018-06-09 22:24 UTC Modified: 2018-06-10 12:13 UTC
From: love at sickpeople dot se Assigned: tpunt (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.3.0alpha1 OS:
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.
Block user comment
Status: Assign to:
Bug Type:
From: love at sickpeople dot se
New email:
PHP Version: OS:


 [2018-06-09 22:24 UTC] love at sickpeople dot se
"$foo" in heredoc works, while "$foo." triggers a ParseError.

For clarity with newlines etc, the script below encoded: PD9waHAKCiRmb28gPSAnZm9vJzsKCmVjaG8gPDw8QkFSCiAkZm9vCiBCQVI7CgplY2hvIDw8PEJBUgogJGZvby4KIEJBUjsKCg==

Test script:
$foo = 'foo';

echo <<<BAR

echo <<<BAR

Expected result:
No ParseError.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-06-09 22:45 UTC]
-Summary: Variables in heredoc does not work properly +Summary: Changed behaviour in unclosed HereDoc
 [2018-06-09 22:45 UTC]
Running you exact code gives me the error "Parse error: syntax error, unexpected end of file in /in/VQqm7 on line 12" -

That's because there are spaces before the "BAR;" in your script, and the parser gets to the end of the file unexpectedly.

Removing those spaces makes the script work - 

However I'm going to leave this open as the error has changed for PHP7.3alpha, and it makes no sense.
 [2018-06-09 22:47 UTC]
tl:dr - the error message for unclosed heredoc makes no sense for PHP 7.3alpaha

Parse error: Invalid body indentation level (expecting an indentation level of at least 1) in /in/VQqm7 on line 10

Parse error: syntax error, unexpected end of file in /in/VQqm7 on line 12
 [2018-06-09 22:47 UTC]
-Status: Open +Status: Verified
 [2018-06-09 22:58 UTC]
In PHP 7.3 the doc string *is* terminated. The code as written should be working fine, the indentation error is spurious.
 [2018-06-09 22:59 UTC] love at sickpeople dot se
The heredoc should not be considered unclosed in 7.3, since .

The dot triggers the problem. With removed dot the script works in 7.3alpha1:
 [2018-06-10 12:13 UTC]
-Assigned To: +Assigned To: tpunt
 [2018-06-10 12:13 UTC]
The problem is that strip_multiline_string_indentation() is called
after *any* variable[1], resulting in the parse error, if the
variable is not followed by whitespace, and resulting in removed
whitespace otherwise.  E.g.

$foo = 'foo';
echo <<<BAR
 $foo bar

outputs `foobar` instead of the expected `foo bar`.

Thomas, could you please have a look at this issue?

[1] <>
 [2018-06-27 12:16 UTC]
Automatic comment on behalf of
Log: Fixed bug #76439
 [2018-06-27 12:16 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Nov 28 17:01:27 2023 UTC