Hi

On 6/30/24 16:16, Juliette Reinders Folmer wrote:
Just a suggestion: what about making the returned array an associative
array ? Like so:
```
array(
      'quotient' => 61,
      'remainder' => 1,
);
```

This would remove the need for devs to remember the order of the return
values and would make the return value self-documenting.


An associative array would combine the worst of an array (no IDE autocompletion, no strong typing, increased memory usage) with the worst of an object (no easy way to extract the values into local variables with array destructuring).

The example in the RFC doesn't show it, but the following makes the proposed API really convenient to use:

    $slicesOfPizza = new BcMath\Number(8);
    $mouthsToFeed = new BcMath\Number(3);
    [$perMouth, $slicesLeft] = $slicesOfPizza->divmod($mouthsToFeed);

Note how the order of values matches the words in the method name. First the result of 'div', then the result of 'mod'.

Best regards
Tim Düsterhus

Reply via email to