Skip to content

PHP Interactive shell input state incorrectly handles quoted heredoc literals. #14189

Closed

Description

@MorganLOCode

Description

In the interactive shell, starting a heredoc statement puts the shell into a state (indicated by prefixing each input line with <<< instead of php) where subsequent lines are part of the string literal until the delimiter is entered. But if the opening delimiter is double-quoted the input state remains stuck in <<< until a double-quoted delimiter is encountered, when execution resumes.

Interactive shell

php > $I = 'You';
php > $foo = <<<"EOF"
<<< > How do $I
<<< > compare?
<<< > EOF;
<<< > $k = 45+19;
<<< > echo $foo;
<<< > echo " When I'm $k?";
<<< > "EOF";
How do You
compare? When I'm 64?

(I'm guessing that the extra "EOF"; line ends up being interpreted as a complete albeit do-nothing statement.)

What I would expect is the same as if double-quotes had not been used: parsing and execution resumes following the closing delimiter, and doesn't require the quoted closing delimiter to unwedge the input state:

Interactive shell

php > $I = 'You';
php > $foo = <<< EOF
<<< > How do $I
<<< > compare?
<<< > EOF;
php > $k = 45+19;
php > echo $foo;
How do You
compare?
php > echo " When I'm $k?";
 When I'm 64?
php >

For the record, single-quoted nowdoc strings behave as expected:

Interactive shell

php > $I = 'You';
php > $foo = <<< 'EOF'
<<< > How do $I
<<< > compare?
<<< > EOF;
php > $k = 45+19;
php > echo $foo;
How do $I
compare?
php > echo " When I'm $k?";
 When I'm 64?
php >

PHP Version

PHP 8.3.7 (also present in 8.3.6).

Operating System

Windows 10

Activity

  1. changed the title [-]PHP CLI input state incorrectly handles quoted heredoc literals.[/-] [+]PHP Interactive shell input state incorrectly handles quoted heredoc literals.[/+] on May 10, 2024
  2. self-assigned this
    on May 10, 2024
  3. added a commit that references this issue on May 10, 2024
    ae41f98
  4. added 3 commits that reference this issue on May 10, 2024
    f365ced
    f88fc9c
    217b753
  5. Roy-Orbison commented on May 17, 2024

    @Roy-Orbison

    I cannot believe it. I ran into this bug just now, came to report it and see that it was found and fixed only a week ago, when it's been around for over 16 years (if the implemented date in the patch from this RFC is accurate).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions