On Mon, 19 Jun 2023, Nicolas Grekas wrote: > > > On my side, I'd very much prefer keeping the constructor of > > > DatePeriod and thus making it non-overloaded with this signature: > > > > > > public function __construct(DateTimeInterface $start, DateInterval > > > $interval, DateTimeInterface|int $end, int $options = 0) {} > > > > That still has an overloaded third argument — DateTimeInterface|int. > > > > Where you trying to suggest to change the current existing > > __construct() to: > > > > public function __construct(DateTimeInterface $start, DateInterval > > $interval, DateTimeInterface $end, int $options = 0) > > > > and then add these two new factory methods? > > > > createFromRecurrences(DateTimeInterface $start, DateInterval $interval, > > int $recurrences, int $options = 0) > > > > createFromISO8601String(string $specification, int $options = 0) > > > > I really meant DateTimeInterface|int, not an overloaded signature but a > union type.
You may call it a union type, but that's still an overloaded signature :-) > My concern is about providing the best path forward. Both deprecating > and providing the alternative in the same version creates a lot of > friction for end users. > > After a quick chat with Mate, I think we should do this union type *in > addition* to adding the new static constructors. > > Then, later on, if future us think it's worth it, we might want to > consider deprecating passing an integer. > > This would provide a path for BC/FC I would fully support. In any case, I don't mind this — I'm actually going to suggest to change the constructor to: public function __construct(DateTimeInterface $start, DateInterval $interval, DateTimeInterface|int $end, int $options = 0) {} And then *only* add: public static function createFromISO8601String(string $specification, int $options = 0): static {} This solves the original problem of not being able to define the signatures in stubs, and also extracts the most problematic of methods into a factory method where it should always have belonged. There would be no additional benefit in creating the other two factory methods. cheers, Derick
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php