This code will work on PHP >= 5.3.9. You can remove the version check and is_a()  usage.