how do i fix a type hinting error?

From the manual

Typed pass-by-reference Parameters

Declared types of reference parameters are checked on function entry, but not when the function returns, so after the function had returned, the argument’s type may have changed.

Given you are immediately assigning a new value to $output, its type declaration is irrelevant. Either omit the type declaration or mark it nullable

function foo(int $one, int $two, ?int &$output): void
    $output = $one + $two;

Of course, this type of pattern is convoluted and makes no sense over something as simple as

function foo(int $one, int $two): int
    return $one + $two;

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top