Hi

Am 2026-06-22 09:21, schrieb [email protected]:
I would go with `divideBy(int|float|self $divisor): self|int|float` where the argument type defines the return type:
* `divideBy(int|float $divisor): self`
* `divideBy(self $divisor): int|float`

PHP doesn't support “method overloading” and that suggestion requires method overloading. At least in spirit: It would require special - static-analysis only - definitions for this signature to make sense to a developer. With the “Deprecate functions with overloaded signatures” RFC (https://wiki.php.net/rfc/deprecate_functions_with_overloaded_signatures) we have specifically deprecated the use of overloaded signatures.

About integer division - I don't think this is the usual case so I would keep that separate (for later) just like `$int / $int = int|float` is the usual case and integer division `intdiv(): int` needs to be handled more explicitly is needed.

“Integer division“ as you call it is the natural inverse of multiplication. I don't think breaking up a Duration into multiple parts of equal length is something unusual. Looking at the other languages we took inspiration from, it's also the only division operation that Java supports.

Best regards
Tim Düsterhus

Reply via email to