phpinspectionsea
phpinspectionsea copied to clipboard
[FR] string library patterns
Description (screenshot):
Hi,
We already match non-optimal patterns with substr. Here is a new one:
$var = 'déjà';
echo substr($var, 1, strlen($var)); // useless third param
echo mb_substr($var, 1, mb_strlen($var)); // useless third param
Furthermore, I saw this pattern at work today:
$var = 'déjà';
echo mb_substr($var, 1, strlen($var)); // string library mismatch
echo substr($var, 1, mb_strlen($var)); // string library mismatch
The risk here is to count with different library and to end up with weird strings in the end: https://3v4l.org/salLv
Thanks
Hm, perhaps we should introduce a rule similar to Php Code Fixer's 'mb_str_functions': like here - https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/src/Fixer/Alias/MbStrFunctionsFixer.php, or it makes sense to target substring/strpos finctions only?
Yeah, it would be cool to help migrate everything :)