mb_substr return type
orklah opened this issue · comments
Hi,
This library is a dependancy of a library we included on our project.
When our IDE(PHPStorm) try to resolve the mb_substr function, there is two results: PHPStorm stubs and symfony/polyfill.
However, when PHPStorm try to resolve return types for mb_substr on symfony/polyfill, it return string|bool which is not the same as the stubs (string only) nor the php.net documentation (string only).
This is due to that line: Mbstring.php#L549
It directly return substr(), which, contrary to mb_substr, can return false on old PHP versions: php.net/substr
It create issues with PHPStorm static analysis of code because of the extra type resolved for this function.
I created this post to discuss about this.
If there is grunt work to do (for example, adding PHPDoc to functions), I can create a PR, I wanted to have different point of views before doing so because I don't know if this is an issue that should be dealt with within the code or in PHPDoc (or not at all?)
Thanks
We could add a test case with an input that make substr return false, then compare the return value with that of the native mb_substr (the test suite will do it automatically), then add a cast to (string)
after the return statement.
Up for giving it a try?
I'll try !