You might be interested to know that in the alternate universe of Phabricator — the magnum opus of a PHP codebase that is the fourth cousin twice removed of Facebook’s internal PHP stack — there was a function not unlike the one you describe:
It’s verbose but I learned a lot from it. For example, returning a more specific type than String can eliminate a large class of security / escaping bugs.
https://github.com/phacility/libphutil/blob/034cf7cc39940b93...
It’s verbose but I learned a lot from it. For example, returning a more specific type than String can eliminate a large class of security / escaping bugs.