NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content
Middle+1 view

How can you make the second part of the previous problem produce 3, without using return or passing an object?

Practice

Asked at

AI answer

If you mean changing a scalar variable so that its value is 3 after the function call, you can pass it by reference and not use return:

function setThree(int &$value): void
{
    $value = 3;
}

$value = 0;
setThree($value);
// $value === 3

This is not passing an object, but the variable is still passed to the function. Global variables also let you avoid return, but they usually make code less clear.