What are the best practices for handling PHP functions with optional parameters, such as the strstr function?

When dealing with PHP functions that have optional parameters, such as the `strstr` function, it is important to handle them properly to avoid unexpected behavior or errors. One common approach is to use default parameter values to ensure that the function behaves as expected even if some parameters are not provided. This can be achieved by checking if the optional parameters are set and assigning default values if they are not.

function custom_strstr($haystack, $needle, $before_needle = false) {
    if($before_needle) {
        return strstr($haystack, $needle, true);
    } else {
        return strstr($haystack, $needle);
    }
}

// Example usage
$haystack = "Hello, World!";
$needle = ",";
$result = custom_strstr($haystack, $needle);
echo $result; // Output: , World!