php.net |  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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: love at sickpeople dot se
New email:
PHP Version: OS:

 

 [2018-06-09 22:24 UTC] love at sickpeople dot se
Description:
------------
"$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
 $foo
 BAR;

echo <<<BAR
 $foo.
 BAR;


Expected result:
----------------
No ParseError.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

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 - https://3v4l.org/19bhe 

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] danack@php.net
tl:dr - the error message for unclosed heredoc makes no sense for PHP 7.3alpaha

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

From
Parse error: syntax error, unexpected end of file in /in/VQqm7 on line 12
 [2018-06-09 22:47 UTC] danack@php.net
-Status: Open +Status: Verified
 [2018-06-09 22:58 UTC] nikic@php.net
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 https://wiki.php.net/rfc/flexible_heredoc_nowdoc_syntaxes .

The dot triggers the problem. With removed dot the script works in 7.3alpha1: https://3v4l.org/VeX0p
 [2018-06-10 12:13 UTC] cmb@php.net
-Assigned To: +Assigned To: tpunt
 [2018-06-10 12:13 UTC] cmb@php.net
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.

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

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

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

[1] <https://github.com/php/php-src/blob/php-7.3.0alpha1/Zend/zend_language_scanner.l#L2589>
    <https://github.com/php/php-src/blob/php-7.3.0alpha1/Zend/zend_language_scanner.l#L2594>
 [2018-06-27 12:16 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=17afe6430fffa6ca646f336dacf34fc5af865390
Log: Fixed bug #76439
 [2018-06-27 12:16 UTC] nikic@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 20:01:28 2024 UTC