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

Unexpected „binary error“ #2899

Closed
staabm opened this issue Jan 26, 2020 · 5 comments
Closed

Unexpected „binary error“ #2899

staabm opened this issue Jan 26, 2020 · 5 comments

Comments

@staabm
Copy link
Contributor

staabm commented Jan 26, 2020

I dont expect this error

https://phpstan.org/r/737b904c-0630-4e1b-9245-893427a584ba

(Or maybe the phpstan error sounds too much like an error and is more a warning)

As the code works as expected https://3v4l.org/tifuR

@ondrejmirtes
Copy link
Member

PHPStan could implement DateFunctionDynamicReturnTypeExtension so it would understand that for some date() arguments, it still produces a numeric string, which can be added to another number.

But you should understand that arithmetic operations between strings and numbers should be penalized, and that's what PHPStan is doing.

Consider doing something like (new \DateTimeImmutable('now'))->modify('+10 years')->format('Y') instead. You're showing the intent much more clearly.

@ondrejmirtes
Copy link
Member

This is now trivial to implemented because PHPStan can now represent an intersection of StringType and AccessoryNumericStringType which is basically a numeric string: phpstan/phpstan-src@1d27c61

@ondrejmirtes
Copy link
Member

Implemented: phpstan/phpstan-src@1053ee7

@staabm
Copy link
Contributor Author

staabm commented Aug 25, 2020

love it, thx!

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants