从网址中删除结尾斜杠

I'm trying to make a url safe for later use. So I want to strip the slashes from the end of the url string.

Actually I'm doing:

function getUrl() {
    $url = "url/with/ending/slashes///";
    if(..someConditions..) {
        $url = false;
    }
    return $url
}

$a = getUrl();

while($a !== $a = rtrim($a, '/'));

So the string can have a string value or a boolean value

There will be any unexpected result or downside when dealing with unexpected values of the string? (like specific strings, booleans values, integers, etc.?)

Check if result is not false before moving forward,

$a = getUrl();
if($a){
   while($a !== $a = rtrim($a, '/'));
}