Workaround for PHP bug #2801

is_resource reports false for closed resources https://bugs.php.net/bug.php?id=28016
still reproducible in php 5.4.30, encodeObject tries to is_utf8 a resource and generates an error that resource was given to mb_detect_encoding instead of string