Repository navigation
Conversation
createFromFormat() and the DateTimeImmutable constructor roll an out-of-range date over (30 February becomes 2 March) and only record a warning, so the coercer accepted it as valid input. A parse with warnings now returns the raw value and the Type constraint reports it. Signed-off-by: JaWitold <witekkaras00@gmail.com>
JaWitold
force-pushed
the
fix/datetime-coercer-rejects-overflowing-dates
branch
2 times, most recently
from
October 29, 2026 10:13
57805af to
e3dc667
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
DateTimeCoercertreated onlyfalsefromcreateFromFormat()(or an exception from the constructor) as a failed parse. PHP rolls an out-of-range date over and records only a warning:So a
\DateTimeImmutableproperty with#[Format('!Y-m-d')]accepted2026-02-30and silently handed the controller 2 March. Same on the no-format path (new \DateTimeImmutable('2026-02-30 10:00:00')).Fix
After parsing, check
\DateTimeImmutable::getLastErrors(); anywarning_count > 0returns the raw value, so the existingTypeconstraint reports it as invalid. Both paths covered. Documented inEXAMPLES.md.Tests
DateTimeCoercerTest: overflowing date with format, overflowing date without format (both red before the fix), trailing garbage with format (pinned, already rejected).PHPStan clean. Full suite: 470 tests, 1 pre-existing unrelated failure on master (
CacheReflectorTest::testUnknownClassReturnsNull).