Skip to content

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

Closed
@MorganLOCode

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions