Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static analyse if date_create_from_format will fail or not #502

Merged

Conversation

pascalheidmann
Copy link
Contributor

@pascalheidmann pascalheidmann commented Apr 22, 2021

Both date_create_from_format and its immutable cousin date_create_immutable_from_format can return DateTime/DateTimeImmutable objects or false on error.

In situations where both $format and $datetime parameters are known (static strings) we can check for results via phpstan and therefore prevent both unnecessary checks during runtime and false positives in phpstan (baseline).

As DateTime::createFromFormat() and DateTimeImmutable::createFromFormat() are both aliases for these functions they are covered as well. OOP variants should work but seem not to do...

…pproaches of both functions to statically determine if it will fail or work if both parameters are static strings
@ondrejmirtes ondrejmirtes merged commit 7375f6c into phpstan:master Apr 22, 2021
@ondrejmirtes
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants