Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Incorrect warning when using functions that return a reference #757

@muglug

Description

@muglug
class A {
    /** @var string */
    public $foo = "bar";
    
    public function &getString() : string {
        return $this->foo;
    }
}

function useString(string &$s) : void {}

$a = new A();
useString($a->getString());

https://phpstan.org/r/da3db779cb2ac821b7ecc9ca8d4a1b71

Expected: No error
Actual: Parameter #1 $s of function useString is passed by reference, so it expects variables only.

Just fixed this in Psalm, was relatively painless.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions