You could instead add here:

    if (empty($hostname)) {
        $error         = self::INVALID_HOSTNAME;
        $validAddress  = false;
        continue;
    }

And ditch the else if block. It is both more readable and understandable.