StrContainsCanBeUsed
info on by default quick-fix PHP ≥ 8.0Group: Language level migration · PhpStorm name: StrContainsCanBeUsedInspection
Comparing a strpos() result strictly against false is the pre-PHP 8 idiom for "does the string contain this substring". PHP 8 has str_contains() for exactly that.
Example
php
<?php
function scan(string $line, string $tag) {
$hit = strpos($line, $tag) !== false;
$hit2 = FALSE !== mb_strpos($line, '#');
$miss = \strpos(trim($line), $tag) === false;
return [$hit, $hit2, $miss];
}php
<?php
function scan(string $line, string $tag) {
$hit = str_contains($line, $tag);
$hit2 = FALSE !== mb_strpos($line, '#');
$miss = !\str_contains(trim($line), $tag);
return [$hit, $hit2, $miss];
}Reported:
- line 3: Replace with 'str_contains($line, $tag)'.
- line 5: Replace with '!\str_contains(trim($line), $tag)'.
Configure
In custos.json:
json
{
"rules": {
"StrContainsCanBeUsed": {
"enabled": false
}
}
}Suppress
Before the statement or declaration (or the first statement of the file), either of:
php
// @custos-ignore StrContainsCanBeUsed
/**
* @noinspection StrContainsCanBeUsedInspection
*/