Skip to content
Advertisement

PhpStorm Expression Expected Using PHP Short Echo Tags Inside HTML Attributes

I found something similar to this while doing a code review, and I don’t see what is wrong with the code (shown as a syntax error by PhpStorm). The problem is using PHP short echo tags in an HTML attribute. PhpStorm doesn’t seem to have a problem with the usage in the label’s for attribute, or the input’s id attribute, but indicates there is an error in the input’s name attribute. Here is a simple way to replicate.

Filename: trash.phtml

<?php
/** ...*/
function getId(): string
{
    return '0';
}
?>
<label for="bundle_me[<?= getId(); ?>]"></label>
<input type="hidden"
       id="bundle_me[<?= getId(); ?>]"
       name="bundle_me[<?= getId(); ?>]"/>

This is PhpStorm 2021.1.4 running on a Linux VM. PHP version 7.4

Screenshot of PhpStorm's code detection having a problem with the name attribute.

Advertisement

Answer

It’s a bug in the Angular plugin: https://youtrack.jetbrains.com/issue/WEB-39052
Has to be fixed by the WebStorm team. In the meanwhile, you can disable the plugin if you are not using Angular.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement