It might be lighter to write this

    if ($path[strlen($path) - 1] !== '/')