Skip to content

Invalid "Class 'ClassName' is not imported" warning in HTML context #153

Description

@magnus-eriksson

I have PHP files that contains HTML (I'm using a templating engine that uses PHP files as templates) like this:

<?php $this->layout('main-layout') ?>

<h1>Page: Hello world</h1>

If I have a <?php ... ?> block or not in the template doesn't matter

If I also have a class named Page anywhere in my code under any namespace, I get a warning that "Class 'Page' not imported" even though it's outside the PHP block and the text "Page" in HTML gets a squiggly yellow line under it.

Just as a test, I imported that class in the top of the template just to see if the warning disappeared, which it did. It however showed the class as unused (which is correct) so it seems like the plugin gets a bit confused.

It would be great if the plugin only parsed the text in PHP context (within <?= ... ?> and <?php ... ?> blocks) and ignored anything outside.

The text "Page" is just an example. It happens for any text I have in HTML that happens to match any PHP class name in the code.
It's not a show stopper, but it does create extra unnecessary noise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions