Skip to content

Invalid "Types-related false-positive" warning in Trait. #1987

@etshy

Description

@etshy
Subject Details
Plugin Php Inspections (EA Extended) 5.3.0
Language level PHP 8.4

Current behaviour

Inside a trait I have an argument typed like this ?self $self = null.
I have the following code that can fill $self if it's null

if ($self === null) {
    try {
        $self = new self();
    } catch (ArgumentCountError) {
        // If the constructor requires arguments, try to create it without calling the constructor
        $reflection = new \ReflectionClass(self::class);
        $self = $reflection->newInstanceWithoutConstructor();
    }
}

The new self() and $reflection->newInstanceWithoutConstructor(); are underlined with type not matching and possible false-positive warning.
Though, even in a Trait, self always equal self.

Expected behaviour

No warning

Environment details

Build #PS-252.23892.419

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