Fix DateInterval::createFromDateString return type for PHP 8.3+#11849
Open
xelaris wants to merge 1 commit into
Open
Fix DateInterval::createFromDateString return type for PHP 8.3+#11849xelaris wants to merge 1 commit into
xelaris wants to merge 1 commit into
Conversation
Since PHP 8.3, DateInterval::createFromDateString() throws DateMalformedIntervalStringException on invalid input instead of returning false. Move the CallMap delta from 8.4 to 8.3 and add a Php83.phpstub override so that both the CallMap and the stub return the correct type.
|
I'm on php8.4, but it is still inferring |
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.
On PHP 8.3 and newer
DateInterval::createFromDateString()throwsDateMalformedIntervalStringExceptionon failure instead of returningfalse(see php/php-src#10366). Psalm still reportsPossiblyFalseReferencewhen calling a method on the return value ofcreateFromDateString, even when targeting PHP 8.3 and newer.See also https://www.php.net/manual/en/dateinterval.createfromdatestring.php#refsect1-dateinterval.createfromdatestring-changelog
The return type change was considered in
CallMap_84_delta.php, but I think it should be inCallMap_83_delta.php.The CallMap lookup seems to be skipped for Psalm's own stubs. I added a
Php83.phpstubthat overrides thecreateFromDateStringdefinition instubs/CoreGenericClasses.phpstubwith return typeDateInterval.psalm/stubs/CoreGenericClasses.phpstub
Lines 624 to 631 in ca15124
There are two new test cases in
CoreStubsTest. One is confirming the return type is stillDateInterval|falsefor PHP 8.2 and the other one is confirming it'sDateIntervalon PHP 8.3.