elgg_instanceof can crash easily

If a non Entity is provided to elgg_instanceof and $type or $subtype is set the function will crash.

example:
$entity = get_entity(0);
elgg_instanceof($entity, 'object', 'blog'); 
this will crash the page.

also my PR improves some logic to don't do unnecessary checks