Bug #76439 [Ver]: Changed behaviour in unclosed HereDoc

From: Date: Sun, 10 Jun 2018 12:13:33 +0000
Subject: Bug #76439 [Ver]: Changed behaviour in unclosed HereDoc
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215582@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76439&edit=1 ID: 76439 Updated by: cmb@php.net Reported by: love at sickpeople dot se Summary: Changed behaviour in unclosed HereDoc Status: Verified Type: Bug Package: Scripting Engine problem PHP Version: 7.3.0alpha1 -Assigned To: +Assigned To: tpunt Block user comment: N Private report: N New Comment: 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> Previous Comments: ------------------------------------------------------------------------ [2018-06-09 22:59:42] 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-09 22:58:12] 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:47:03] 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:45:55] 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:24:09] 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76439&edit=1

« previous php.bugs (#215582) next »