What are the best practices for handling non-Boolean return values in PHP functions like strpos?

When using functions like strpos in PHP that return non-Boolean values, it's important to handle the return value appropriately to avoid unexpected behavior. One common approach is to check if the function returns false to indicate that the substring was not found, and then handle that case accordingly. This can be done using strict comparison (===) to differentiate between a false return value and a position of 0.

$haystack = "Hello, world!";
$needle = "world";

$pos = strpos($haystack, $needle);

if ($pos !== false) {
    echo "Substring found at position: " . $pos;
} else {
    echo "Substring not found.";
}