bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.64k stars 94 forks source link

Odd type error #2577

Closed designermonkey closed 7 months ago

designermonkey commented 1 year ago

Describe the bug

When I use the code below, intelephense tells me that the $clone variable is Expected type 'object'. Found 'string'. intelephense(1006).

I don't understand how that can be the case unless I've missed something obvious.

To Reproduce

    public function withFields(Fields $fields): self
    {
        $reflection = new ReflectionClass(static::class);
        $scope = $reflection->getProperty('fields')->getDeclaringClass()->getName();
        $clone = $reflection->newInstanceWithoutConstructor();

        if (self::class === $scope) {
            $clone->fields = $fields;
        }

        return $this;
    }

Expected behavior

That there is no error.

Screenshots

image

Platform and version

Mac OS Ventura 13.3, Code 1.77.0 and Intelephense v1.9.5

bmewburn commented 7 months ago

Can't repro in 1.10.4