How can passing null to the parameter #1 of substr() in PHP be avoided to prevent deprecated warnings?

When passing null to the parameter #1 of substr() in PHP, it can lead to deprecated warnings as of PHP 7.1. To avoid this, you can explicitly check if the string is empty or null before calling substr(). This ensures that substr() is only called when a valid string is provided.

// Check if the string is not empty or null before calling substr()
if (!empty($string)) {
    $result = substr($string, $start, $length);
} else {
    $result = ''; // or any default value you want to set
}