Ulterior information on this patch:
As per php.net/manual/en/filter.filters.validate.php: FILTER_VALIDATE_DOMAIN
Validates domain names against RFC 1034, RFC 1035, RFC 952, RFC 1123, RFC 2732, RFC 2181, and RFC 1123. Optional flag FILTER_FLAG_HOSTNAME adds ability to specifically validate hostnames (they must start with an alphanumberic character and contain only alphanumerics or hyphens).
filter_var() returns false on failure or the entire unmodified input string on success, on this the patch removes any valid trailing dot before counting parts.
Sure the patch could be modified to trim and count on success only.
Above RFCs are pretty old but updated only for domain DNS names, records with underscore, and SMTP mail transport specifications.
This patch will not validate a domain DNS name such as _tcp.example.test, as I suppose is_fqdn() target RFC 1123.
bool(true) 'sub.domain.test.'
bool(true) 'sub.domain.test'
bool(true) 'xn--sub.xn--domain.test'
bool(false) 'domain.test.'
bool(false) 'domain.test'
bool(false) '-sub.domain.test'
bool(false) '_sub.domain.test'
bool(false) 's_ub.domain.test'