Skip to content

infer numeric types on ctype_digit() #1615

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

Closed
wants to merge 2 commits into from
Closed

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Aug 12, 2022

@staabm staabm marked this pull request as ready for review August 12, 2022 15:53

function foo($mixed, string $s) {
if (ctype_digit($mixed)) {
assertType('float|int|numeric-string', $mixed);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using ctype_digit on non-strings is deprecated but still allowed

assertType('float|int|numeric-string', $mixed);
return;
}
assertType('mixed~float|int', $mixed);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can still be int if $mixed is 42 for example. The difference between ctype_digit and is_numeric is described in the docs https://www.php.net/manual/en/function.ctype-digit.php, this will need custom extension that probably takes advantage of IntegerRangeType or something...

@staabm staabm closed this Aug 19, 2022
@staabm staabm deleted the ctype_digit branch August 19, 2022 12:07
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.

ctype_digit assertion on string must imply numeric-string as is_numeric does
2 participants