Skip to content

infer numeric types on ctype_digit()#1615

Closed
staabm wants to merge 2 commits intophpstan:1.8.xfrom
staabm:ctype_digit
Closed

infer numeric types on ctype_digit()#1615
staabm wants to merge 2 commits intophpstan:1.8.xfrom
staabm:ctype_digit

Conversation

@staabm
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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