Re: [RFC] Duration class

From: Date: Mon, 22 Jun 2026 17:36:08 +0000
Subject: Re: [RFC] Duration class
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to internals+get-131470@lists.php.net to get a copy of this message
Hi Am 2026-06-22 09:21, schrieb marc@mabe.berlin:
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

« previous php.internals (#131470) next »