Skip to content

require_once above use statement breaks namespace resolution #6348

@W0rma

Description

@W0rma

Bug report

The following code does not cause any errors (https://phpstan.org/r/a18abfec-c963-4f5b-afcf-416f557f34f3):

namespace abc;

use foo\bar;

require_once '';

/** @var bar $x */
$x = new bar();

However, adding require_once between namespace and use statement causes the error PHPDoc tag @var for variable $x contains unknown class abc\bar. (https://phpstan.org/r/5dd10c66-6a6b-48c4-9cc7-43808b0071af):

namespace abc;

require_once '';

use foo\bar;

/** @var bar $x */
$x = new bar();

Worked until v1.2
Broken in v1.3.3

The bug looks similar to #6252

Code snippet that reproduces the problem

https://phpstan.org/r/5dd10c66-6a6b-48c4-9cc7-43808b0071af

Did PHPStan help you today? Did it make you happy in any way?

Thank you for developing this great tool!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions