Skip to content

Wrong return type #1903

@nospor

Description

@nospor

Hi, I have a function which returns an array but phpstan says, it returns null

Method Test::test() should return array but returns null. 

This is the code:

class Test {
    private $answersOrder = [];
    public function test(string $qId): array
    {
        if (null !== $this->answersOrder[$qId]) {
            return $this->answersOrder[$qId];
        }


        $this->answersOrder[$qId] = 5;

        return $this->answersOrder[$qId];
    }

}

As you can see it always returns an array. I think that first IF block confuses phpstan somehow

Expected output

There shouldnt be any error for that class

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions