[php-src] Issue #9637: Select the first of month as day when creating a date without day

From: Date: Thu, 29 Sep 2022 12:34:58 +0000
Subject: [php-src] Issue #9637: Select the first of month as day when creating a date without day
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-242492@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/9637 Author: bwoebi ### Description While it is consistent and logical, I've never seen a case where using the current day of month was the desired behaviour when selecting only a month (or year and month). It just ends up always being a big footgun, exploding in someones production code after 1-60 days. What nearly everyone wants, when he writes that code, is a day within that month. So that code like: ``` $dateTime = DateTime::createFromFormat('Y-m', '2022-02'); print $dateTime->format('Y-m') . PHP_EOL; ``` will indeed return 2022-02, independently of the current day. If you actually want to preserve the behaviour, it is trivial by being explicit as in writing '2022-02-' . date('d'). I'm essentially asking here - as a feature for a future version 8.2 or 8.3+ - this behaviour being changed to be less surprising to developers, and in particular idempotent relative to the current date. I'm aware this is special casing, but a special case giving a better developer experience.

« previous php.bugs (#242492) next »