php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77812 Interactive mode does not support PHP 7.3-style heredoc
Submitted: 2019-03-27 20:13 UTC Modified: 2019-08-23 12:06 UTC
Votes:5
Avg. Score:3.8 ± 0.7
Reproduced:4 of 5 (80.0%)
Same Version:4 (100.0%)
Same OS:2 (50.0%)
From: bugs dot php dot net at ss dot st dot tc Assigned: cmb (profile)
Status: Closed Package: Readline related
PHP Version: 7.3 OS: *
Private report: No CVE-ID: None
 [2019-03-27 20:13 UTC] bugs dot php dot net at ss dot st dot tc
Description:
------------
Old, pre-7.3 heredoc syntax works as expected in PHP 7.3 interactive shell:

$ php7.3 -a
Interactive shell

php > echo <<<FOO
<<< > bar
<<< > FOO;
bar


Now let's try 7.3 heredoc syntax:

$ php7.3 -a
Interactive shell

php > echo <<<FOO
<<< >     bar
<<< >     FOO;
<<< >


$ php7.3 -a
Interactive shell

php > print(<<<FOO
<<< > xx
<<< > FOO);
<<< >


$ php7.3 -a
Interactive shell

php > echo <<<FOO
<<< >     xxx
<<< >     FOO;
<<< > FOO
php > ;
xxxPHP Warning:  Use of undefined constant FOO - assumed 'FOO' (this will throw an Error in a future version of PHP) in php shell code on line 4


The latter example works well in PHP 7.2:

$ php7.2 -a
Interactive shell

php > echo <<<FOO
<<< >     xxx
<<< >     FOO;
<<< > FOO
php > ;
    xxx
    FOO;
php >


Patches

fix-77812 (last revision 2019-08-17 15:54 UTC by cmb@php.net)

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-03-28 00:03 UTC] a at b dot c dot de
This is the first entry listed under the "Backward Incompatible Changes" section of the 7.3 migration guide.

http://www.php.net/manual/en/migration73.incompatible.php
 [2019-03-28 00:11 UTC] bugs dot php dot net at ss dot st dot tc
-Status: Open +Status: Closed
 [2019-03-28 00:11 UTC] bugs dot php dot net at ss dot st dot tc
Oh thank you so much. I didn't look there.
Instead, was staring at https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc which doesn't even mention new syntax.
Thanks again.
 [2019-03-28 09:54 UTC] cmb@php.net
-Summary: 7.3 Interactive shell won't digest 7.3 heredoc syntax +Summary: 7.3 heredoc syntax not documented in manual proper -Status: Closed +Status: Re-Opened -Type: Bug +Type: Documentation Problem -Operating System: Linux (didn't try Win) +Operating System: * -PHP Version: 7.3.3 +PHP Version: 7.3
 [2019-03-28 09:54 UTC] cmb@php.net
> […] which doesn't even mention new syntax.

Re-opening as doc bug, then.
 [2019-04-03 17:54 UTC] chasepeeler at gmail dot com
The documentation at https://www.php.net/manual/en/migration73.incompatible.php#migration73.incompatible.core.heredoc-nowdoc is definitely wrong.

As written:
<?php
$str = <<<FOO
abcdefg
   FOO
FOO;
?>

will not produce the error mentioned. Instead, it will give the following:
Parse error: Invalid body indentation level (expecting an indentation level of at least 4)

If you don't indent that line:
<?php
$str = <<<FOO
abcdefg
FOO
FOO;
?>

You'll get an error, but still not the one reported. This appears to be a bug though, as it's requiring a semicolon after the identifier, despite the fact that documentation says that is no longer required. See https://bugs.php.net/bug.php?id=76608
 [2019-04-03 21:07 UTC] chasepeeler at gmail dot com
So, it doesn't appear the other issue I mentioned in my previous email is actually a bug. The fact that the migration documentation is incorrect still applies, though.
 [2019-08-01 21:24 UTC] santiagoarizti at gmail dot com
The problem in php interactive mode is still there. Here I show How I create a php file and add a simple function that echoes a string from a heredoc.
But the same function in interactive mode is not even recognized as a complete heredoc, so I cannot even close the function. see this:

santiagoarizti@santis-mac:~$ docker run --rm -it php:7.3 bash
root@a8df21f382dd:/# echo -e '#!/usr/local/bin/php\n<?php\nfunction sayHello($name) {\n  echo <<<EOF\n    hola $name\n    EOF;\n}\nsayHello($argv[1]);echo PHP_EOL;\n' > santi.php
root@a8df21f382dd:/# cat santi.php 
#!/usr/local/bin/php
<?php
function sayHello($name) {
  echo <<<EOF
    hola $name
    EOF;
}
sayHello($argv[1]);echo PHP_EOL;

root@a8df21f382dd:/# php santi.php Santiago
hola Santiago
root@a8df21f382dd:/# php -a
Interactive shell

php > function sayHello($name) {
php {   echo <<<EOF
<<< >     hola $name
<<< >     EOF;
<<< > }

Notice how I am still inside heredoc according to php.

Here is a simpler example without anything but an echo:

santiagoarizti@santis-mac:~$ docker run --rm -it php:7.3     
Interactive shell

php > echo <<<EOF
<<< > this works fine, 
<<< > old syntax
<<< > EOF;
this works fine,
old syntax
php > echo <<<EOF
<<< >   this doesn't
<<< >   work, new syntax
<<< >   EOF;
<<< >
 [2019-08-01 21:33 UTC] santiagoarizti at gmail dot com
Ok, after a little bit more playing around with interactive mode, I found the problem, but I cannot fix it. The php interpreter is ok, it is just the interactive mode that is not recognizing the end of the flexible heredoc. But, with this combination of lines the interpreter behaves "correctly"

santiagoarizti@santis-mac:~$ docker run --rm -it php:7.3
Interactive shell

php > echo <<<EOF
<<< >   let us see
<<< >   EOF /*
<<< > EOF
php > */
php > ;
let us see
php > 

I gave the interpreter the old expected ending, but inside a multiline comment, so it doesn't complain about a missing constant... perhaps that gives an idea of what is causing the issue
 [2019-08-17 12:10 UTC] blackknight at iinet dot net dot au
Would it be worth splitting this into two issues? This one is currently classified as a documentation issue, but the interactive mode issue seems quite distinct.
 [2019-08-17 12:19 UTC] requinix@php.net
-Summary: 7.3 heredoc syntax not documented in manual proper +Summary: Interactive mode does not recognize PHP 7.3-style heredoc closing identifier -Type: Documentation Problem +Type: Bug -Package: Strings related +Package: Unknown/Other Function
 [2019-08-17 12:19 UTC] requinix@php.net
I've split the doc bug out into bug #78425, since this report has a fair bit of commentary about the interactive mode bug.
 [2019-08-17 12:22 UTC] requinix@php.net
-Package: Unknown/Other Function +Package: Readline related
 [2019-08-17 12:22 UTC] requinix@php.net
Looks like the fix will be to ext/readline's cli_is_valid_code().
 [2019-08-17 12:49 UTC] blackknight at iinet dot net dot au
I've just had a look around and it might be a bit fiddly to fix. Around line 354 of ext/readline/readline_cli.c.
Allowing whitespace between the start of line and the heredoc tag shouldn't be too difficult, but the new syntax also allows the tag to be followed by code other than just `\n` or `;\n` - will need some way to distinguish `   END, $somethingElse);` from `    ENDING inside the heredoc`.
 [2019-08-17 15:54 UTC] cmb@php.net
The following patch has been added/updated:

Patch Name: fix-77812
Revision:   1566057240
URL:        https://bugs.php.net/patch-display.php?bug=77812&patch=fix-77812&revision=1566057240
 [2019-08-21 11:45 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #77812: Interactive mode does not support PHP 7.3-style heredoc
On GitHub:  https://github.com/php/php-src/pull/4590
Patch:      https://github.com/php/php-src/pull/4590.patch
 [2019-08-23 12:05 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=03c7749dc8f40df8f41afffcdef4595ad43afe7f
Log: Fix #77812: Interactive mode does not support PHP 7.3-style heredoc
 [2019-08-23 12:05 UTC] cmb@php.net
-Status: Re-Opened +Status: Closed
 [2019-08-23 12:06 UTC] cmb@php.net
-Summary: Interactive mode does not recognize PHP 7.3-style heredoc closing identifier +Summary: Interactive mode does not support PHP 7.3-style heredoc -Assigned To: +Assigned To: cmb
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 13 14:01:27 2024 UTC