src/Hostname.php
private static function myValidateTld(?string $tld, ?string &$error): bool
    {
        if ($tld === null) {
            return true;
        }

        if ($tld === '') {
            $error = 'Top-level domain "' . $tld . '" is empty.';

            return false;
        }

        if (strlen($tld) > 63) {
            $error = 'Top-level domain "' . $tld . '" is too long: Maximum allowed length is 63 characters.';

            return false;
        }

        if (preg_match('/[^a-zA-Z]/', $tld, $matches)) {
            $error = 'Top-level domain "' . $tld . '" contains invalid character "' . $matches[0] . '".';

            return false;
        }

        return true;
    }
private static function myValidateTld(?string $tld, ?string &$error): bool
    {
        if ($tld === null) {
            return true;
        }

        if ($tld === '') {
            $error = 'Top-level domain "' . $tld . '" is empty.';

            return false;
        }

        if (strlen($tld) > 63) {
            $error = 'Top-level domain "' . $tld . '" is too long: Maximum allowed length is 63 characters.';

            return false;
        }

        if (preg_match('/[^a-zA-Z]/', $tld, $matches)) {
            $error = 'Top-level domain "' . $tld . '" contains invalid character "' . $matches[0] . '".';

            return false;
        }

        return true;
    }
private static function myValidateTld ( ? string $ tld , ? string & $ error ) : bool { if ( $ tld === null ) { return true ; } if ( $ tld === '' ) { $ error = 'Top-level domain "' . $ tld . '" is empty.' ; return false ; } if ( strlen ( $ tld ) > 63 ) { $ error = 'Top-level domain "' . $ tld . '" is too long: Maximum allowed length is 63 characters.' ; return false ; } if ( preg_match ( '/[^a-zA-Z]/' , $ tld , $ matches ) ) { $ error = 'Top-level domain "' . $ tld . '" contains invalid character "' . $ matches [ 0 ] . '".' ; return false ; } return true ; }
Validates a top-level domain.

@param string|null $tld   The top-level domain.
@param string|null $error The The error text if validation was not successful, undefined otherwise.

@return bool True if validation was successful, false otherwise.
Validates a top - level domain .