-
-
Notifications
You must be signed in to change notification settings - Fork 23
Return type for integers should be numeric-string #222
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
Comments
Now the sad thing with numeric-string is we lose the integer ranges :) |
yeah, I guess this would only work as a big union of all possible values (and this is limited to at max 256 possible unique values by phpstan) |
Yeah that or you'd need numeric-string<x,y> syntax support in phpstan. That would be better but not sure it's worth it. |
per https://stackoverflow.com/a/20123337 it should be possible using regular int etc |
Hmm ok.. need to check the real runtime output I get, maybe my code is broken :D |
OK confirming I get Now if I do It does seem like PHP 8.1 however returns correct types by default as per php/php-src@c18b1ae - so that's some good news. I'm not sure if the code here should only assume int returns for 8.1, or if it should be an option in the phpstan config (as emulated prepare statements is the default AFAIK, it should probably default to numeric-string on php<8.1 and ints on php8.1+). |
Thanks for investigating. Thats great news. We will have a new RuntimeConfiguration switch then, with which you can tell phpstan-dba how types should be handled https://github.com/staabm/phpstan-dba/blob/main/src/QueryReflection/RuntimeConfiguration.php |
Also note that I just noticed this only says PDO MySQL in the PHP changelog. It may not apply to other DBs. |
php/php-src@c18b1ae also mentions a |
I did try, it said it is not available for mysqlnd.. Maybe in PHP 8.1 it becomes available to revert to the old mode, that's my understanding from changelog anyway. |
just landed a new https://github.com/staabm/phpstan-dba#runtime-configuration |
Great thanks, seems to work fine :) |
This code here:
Triggered:
At least with doctrine connection like this it appears to really return
'1'
. I am not sure if there are cases where PDO will return the proper integers, or perhaps with Doctrine when using query builder it may have smarter return values. Would need to all be verified.The text was updated successfully, but these errors were encountered: