PhpStorm Expression Expected Using PHP Short Echo Tags Inside HTML Attributes
Get the solution ↓↓↓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
Answer
Solution:
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.
Answer
Solution:
Looking at your screenshot -- the name attribute value has different (light green) background... which tells that you have somehow injected another language there.
Settings/Preferences | Editor | Language Injections
- Look at all entries there where
Scope
column has "IDE" or "Project" values. - Locate and disable unexpected rule (most likely will be HTML or XML +
name
and/orinput
mentioned) - If all good -- you can now delete that wrong rule.
- If not sure: post that screen with IDE & Project scope rows.
- If still nothing -- could be some plugin (AFAIK bundled Angular plugin has similar kind of issues...)
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: cannot use isset() on the result of an expression (you can use "null !== expression" instead)
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.