private static function myParse(string $hostname, ?array &$domainParts = null, ?string &$tld = null, ?string &$error = null): bool
    {
        if ($hostname === '') {
            $error = 'Hostname "' . $hostname . '" is empty.';

            return false;
        }

        if (strlen($hostname) > 255) {
            $error = 'Hostname "' . $hostname . '" is too long: Maximum allowed length is 255 characters."';

            return false;
        }

        $domainParts = explode(
            '.',
            substr($hostname, -1) === '.' ? substr($hostname, 0, -1) : $hostname // Remove trailing "." from hostname.
        );

        // Is there a top-level domain?
        $tld = count($domainParts) > 1 ? array_pop($domainParts) : null;

        if ($tld !== null) {
            if (!self::myValidateTld($tld, $error)) {
                $error = 'Hostname "' . $hostname . '" is invalid: ' . $error;

                return false;
            }
        }

        // Validate the domain parts.
        if (!self::myValidateDomainParts($domainParts, $error)) {
            $error = 'Hostname "' . $hostname . '" is invalid: ' . $error;

            return false;
        }

        // Normalize result.
        self::myNormalizeDomainParts($domainParts);
        self::myNormalizeTld($tld);

        return true;
    }