CaseInsensitiveStringFunctionsMissUse
warning on by default quick-fixGroup: Performance · PhpStorm name: CaseInsensitiveStringFunctionsMissUseInspection
Case-insensitive search functions (stripos, strripos, stristr) do extra case-folding work. When the needle has no letters at all (e.g. '/', '::', '42'), case does not matter and the plain case-sensitive counterpart gives the same result faster.
Example
php
<?php
function parts($path, $mode)
{
$sep = '::';
$a = stripos($path, '/');
$b = strripos($path, '.', -2);
$c = \stristr($path, $sep);
$d = stripos($path, "2024");
$e = stripos($path, 'x');
$f = strripos($path, 'ß');
$g = stristr($path, '');
$h = stripos($path, "\t");
$i = stripos($path, $mode);
$j = stripos($path);
return [$a, $b, $c, $d, $e, $f, $g, $h, $i, $j];
}php
<?php
function parts($path, $mode)
{
$sep = '::';
$a = strpos($path, '/');
$b = strrpos($path, '.', -2);
$c = \strstr($path, $sep);
$d = strpos($path, "2024");
$e = stripos($path, 'x');
$f = strripos($path, 'ß');
$g = stristr($path, '');
$h = strpos($path, "\t");
$i = stripos($path, $mode);
$j = stripos($path);
return [$a, $b, $c, $d, $e, $f, $g, $h, $i, $j];
}Reported:
- line 5: Needle has no letters; use 'strpos(...)' instead.
- line 6: Needle has no letters; use 'strrpos(...)' instead.
- line 7: Needle has no letters; use 'strstr(...)' instead.
- line 8: Needle has no letters; use 'strpos(...)' instead.
- line 13: Needle has no letters; use 'strpos(...)' instead.
Configure
In custos.json:
json
{
"rules": {
"CaseInsensitiveStringFunctionsMissUse": {
"enabled": false
}
}
}Suppress
Before the statement or declaration (or the first statement of the file), either of:
php
// @custos-ignore CaseInsensitiveStringFunctionsMissUse
/**
* @noinspection CaseInsensitiveStringFunctionsMissUseInspection
*/