1 view
How can you make the second part of the previous problem produce 3, without using return or passing an object?
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.
Also asked at AutoSpot
- Tell us about yourself as a developer — experience, stack, projects.
- What are your salary expectations?
- Do you have experience writing and working with native SQL queries or similar low-level commands to a database?
- What AI tools do you use and for what tasks?
- What do you know about indexes? How can you determine which indexes are used in a query, and how can you tell which indexes are unnecessary or missing?
Similar questions
- In PHP, can you swap characters/variables without allocating a `$temp` variable and without using functions?
- How can an external parameter be passed to an anonymous function?
- What is the result of subtracting 1 - 0.7 - 0.3, and why?
- What if we needed to reverse a string containing Cyrillic characters? Would this implementation work, and what would need to change?
- What is the time and space complexity of your implementation?