-
Notifications
You must be signed in to change notification settings - Fork 548
Add support for int and bool args for strlen #1162
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
Add support for int and bool args for strlen #1162
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would toString also work here instead of these 3 separated cases?
(let the type system decide whether the scalar is castable to string)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toString returns PHPStan\Type\Type.
I don't see any way to get value from it, maybe I don't understand how to do it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about it, but I guess this could work:
$toStringType = $constantScalar->toString();
if ($toStringType instanceof ConstantStringType) {
$len = strlen($toStringType->getValue());
}your added tests will tell :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about float?
https://3v4l.org/XVRAE
maybe even null?
https://3v4l.org/J1pbq
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
I will add support for these
|
I wonder how useful these are if this error is reported on them? https://phpstan.org/r/71827703-d925-432a-87a9-2e8b6fbbb291 |
This kind of errors can be manually suppressed, and return value can be used in the further calculations. I think it would be better (or at least it costs nothing) that PHPStan would be able to figure out the length of vars that are actually acceptable by |
|
Thank you. Please send any modifications as a future PR. |
No description provided.