Use is_object instead of gettype($) == 'object'