diff --git a/lib/byte_safe_strings.php b/lib/byte_safe_strings.php index ae3b7b9..dec5d30 100644 --- a/lib/byte_safe_strings.php +++ b/lib/byte_safe_strings.php @@ -125,6 +125,14 @@ function RandomCompat_substr($binary_string, $start, $length = null) ); } + // Consistency with PHP's behavior + if ($start === RandomCompat_strlen($binary_string) && $length === 0) { + return ''; + } + if ($start > RandomCompat_strlen($binary_string)) { + return false; + } + return mb_substr($binary_string, $start, $length, '8bit'); }