question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Strange bug in PHP files with HTML and Emmet parser because conditionals are been mistaken as opening and/or closing tags

See original GitHub issue

Issue Type: Bug

  1. Open or create a PHP file
  2. Type the following example code:
<?php
$looping = 1;
$while = [];

while ($looping <= 5) {
//here you can't use emmet or html! give it a try!
    $while[] = $looping;
    $looping++;
}
var_dump($while);

$looping = 5;
$while = [];

do {
    $while[] = $looping;
    $looping--;
} while ($looping >= 1);
var_dump($while);

//here you can use emmet and html

for ($i = 1; $i <= 10; ) {
    //here you can't use emmet or html. give it a try!
}

Expected result: Emmet and HTML should continue working and the parser should correctly identify conditionals as not part of an opening or ending tag statement.

Tested without any extensions enabled. It is a core php bug in the editor.

Screenshots to illustrate the actual results with current stable version: Emmet and HTML parsing does not work after using the conditional, because it is trying to parse it as an opening tag bug-report-php-language-html-not-working

Here the parsing works, because the while and do-while have complement conditionals, thus opening and closing a tag, for the html parser bug-report-php-language-html-not-working-2

Just to make it more clear about the opening/closing tag described above bug-report-php-language-html-not-working-3

It is a parsing bug because it will resume working after typing the matched closing tag even in a comment bug-report-php-language-html-not-working-4

I love VSCode and it has been really productive in my daily PHP work. I hope the issue gets addressed and fixed. Thank you for your time and attention on reading this lengthy report.

VS Code version: Code 1.45.1 (5763d909d5f12fe19f215cbfdd29a91c0fa9208a, 2020-05-14T08:27:35.169Z) OS version: Windows_NT x64 10.0.18363

System Info
Item Value
CPUs Intel® Core™ i7-3770K CPU @ 3.50GHz (8 x 3492)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
viz_display_compositor: enabled_on
viz_hit_test_surface_layer: disabled_off_ok
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 11.95GB (7.36GB free)
Process Argv
Screen Reader no
VM 0%
Extensions (4)
Extension Author (truncated) Version
vscode-intelephense-client bme 1.3.11
vscode-toggle-quotes Bri 0.3.2
path-autocomplete ion 1.13.6
google-fonts lio 0.0.1

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
rzhao271commented, Dec 29, 2020

The Emmet extension for VS Code is currently using @emmetio/html-matcher to parse the HTML document, and even the latest version of that completely skips HTML content within PHP tags.

I’ll flag this as an upstream issue, and until there is a better Emmet parser for PHP files I don’t see this issue being fixed for a while.

1reaction
JohnLukeBentleycommented, Jun 26, 2021

Just to provide a minimal example to drive home @weidmaster’s well observed bug.

Create temp.php as follows (retyping at the relevant points):

<?php

// <= The parser takes that to be some kind of opening tag, even in a comment.

// Type the following then tab: emmet fails to trigger
li*4

// >= The parser takes that to be some kind of closing tag, even in a comment.

// Type the following then tab: emmet works.
li*4

?>

With that file I can reproduce @weidmaster’s bug, with extensions disabled, in VS Code 1.51.1. 1.57.1.

Edit: Corrected typo in VS Code version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PHP: xml_parser "Mismatched tag"-error when parsing HTML ...
Obviosly, the reason is: xml_parser() doesn't know that the tags <img> and <br> do not need to be closed (as they are self-closing...
Read more >
I'm confused about php script tags being opened and closed ...
I'm not following the logic of how this works. If the php script tags are were the magic happens, how can there be...
Read more >
code formatting - Closing tag (?>) on PHP files?
This is a difficult bug to spot because you can find it in any file anywhere. The usual way to do is putting...
Read more >
Untitled - Snap!
... ,coffee,files,selling,station,completed,vision,guess,famous,chief,opened ... ,regards,asian,residential,closing,aircraft,shut,thinks,opposed,mistake ...
Read more >
Untitled
Challagundla gardens, Fre 106, Adakah anwar bersalah, Lucia breakin 2, Cannot open youbot driver, Corazon dolido corazon salvaje, Rem end of the world...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found