Massive copy/paste bug (indented HEREDOC breaks the parser)

Often times, but not always) when I copy/paste a block of text in PhpStorm, it totally messed it up -- basically blanks a large chunk of code at the destination.  This has been happening for months now; I'm sorry I can't say exactly what version of PhpStorm started it.  (Currently on 2019.1)

A video is worth a thousand words.  This shows drag/drop, but it does the exact same thing if I use ctrl-x / ctrl-v

https://www.dropbox.com/s/tx8ssc3z2cs5g1y/PhpStorm%20bug%20video.mp4?dl=0

UPDATE: see my first comment below

4 comments

I've figured out where the bug is. It appears that an indented HEREDOC string (introduced in PHP 7.3 and reportedly supported by PhpStorm) breaks the parser.  The document after an indented HEREDOC exhibits the broken Paste behavior show above.

0

I have tried a much simpler example but it works fine for me. Could you please share a piece of code to reproduce the issue without re-typing it from the video?

0

Here's a test case of weirdness:

<?php
$name = 'Steve';
echo <<<HTML
<h1>Hi there</h1>
<p>Hello, $name. This is a test</p>
HTML;
$var = '';
?>
<p>
Something something <?=$var?>
</p>

<?php
$var .= "Hi There. ";
$var .= "What's Up. ";

?>
<p>
Something else
</p>
<?php

echo "<p>$var</p>";

Put your cursor after the `?>` on line 8, and hit Enter.  The following HTML paragraph turns into:

<p>
Something something Something something Something something Something something <?=$var?>
</p>

It seems to be a combination of indented HEREDOC, and using the `<?=$something?>` syntax within HTML ...?  If both of those things are present, hilarity ensues.  Remove the indent on the HEREDOC, and everything works as it should.

0

Thanks for an example! This is caused by https://youtrack.jetbrains.com/issue/WI-45986, fixed in the next major IDE version (2019.2)

1

Please sign in to leave a comment.