Skip to content

Check that values passed to array_sum/product are castable to number #3658

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

Conversation

schlndh
Copy link
Contributor

@schlndh schlndh commented Nov 23, 2024

Fixes phpstan/phpstan#11883

It's largely a copy-paste of ParameterCastableToStringRule (#3132). I checked php-src and as far as I can tell this is the code that's used by array_sum/array_product to convert objects to numbers. It seems to correspond to Type::toNumber() in PHPStan.

It seems that resource worked before PHP 8.3, but I'd report it anyway, since I can't imagine a scenario where you'd want array_sum/array_product over resources: https://3v4l.org/lF7SE

@schlndh schlndh force-pushed the feature-checkArraySumAndProductParamCastableToNumber branch 2 times, most recently from 0f33997 to 9702612 Compare November 23, 2024 12:33
@schlndh schlndh force-pushed the feature-checkArraySumAndProductParamCastableToNumber branch from 9702612 to 11a974f Compare November 23, 2024 12:43
@ondrejmirtes ondrejmirtes merged commit e3867c0 into phpstan:2.0.x Nov 24, 2024
425 of 426 checks passed
@ondrejmirtes
Copy link
Member

Awesome, 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
Development

Successfully merging this pull request may close these issues.

Enums used in array_sum & array_product emit warning since PHP 8.3, but not reported
2 participants