Hi Internals,

I created my first php-src PR <https://github.com/php/php-src/pull/13845> yesterday and anticipate I may have to write an RFC for it. I created a wiki account under the handle, "bilge", and the howto <https://wiki.php.net/rfc/howto> told me to request RFC karma here.

About the PR: I sometimes find it would be useful to only update part of the date. The PR makes all parameters to DateTime(Immutable)::setDate <https://www.php.net/manual/en/datetimeimmutable.setdate.php> optional in a backwards-compatible manner such that we can elect to update only the day, month, year or any combination of the three (thanks, in part, to named parameters). Without this modification, we must always specify all of the day, month and year parameters to change the date.

To change just one part of the date, StackOverflow users have found various novel <https://stackoverflow.com/questions/60415815/setting-just-the-year-with-php-datetime> ways <https://stackoverflow.com/questions/18176794/adjust-a-php-date-to-the-current-year> to work around setDate()'s current limitation, which generally involves calling format() twice, to isolate the specific date parts that should remain constant, and feeding them back into setDate() so they are effectively unchanged. All this leads me to wonder why we can't just call setDate() with only the parameters we want to change. This is particularly useful when generating a collection of dates that only differ in one aspect (year, day) and/or when working in a templating environment, such as Twig, where doing all the format calls results in multiple statements and logic overhead that we should like to avoid in templating contexts.

Looking forward to hearing your thoughts.

Cheers,
Bilge

Reply via email to