Snippet error
Closed this issue · 2 comments
coffeecore commented
Hello.
I think this snippet is wrong :
https://github.com/petrovicstefanrs/30_seconds_of_knowledge/blob/master/src/assets/snippets/php/isContains.md
function isContains($string, $needle)
{
return strpos($string, $needle);
}
strpos
function can return int
or false
. If you do :
if (isContains('abcd', 'abc')){
}
Condition is false
because (bool) 0 === false
.
petrovicstefanrs commented
@coffeecore Yep, nice catch! What do you think if I just fix it to this:
function isContains($string, $needle)
{
return strpos($string, $needle) != -1;
}
coffeecore commented
I think better way :
function isContains($string, $needle)
{
return false !== strpos($string, $needle);
}