Trying to get property 'type' of non-object