How to check an elements elementType In Craft 3, I've got a service function that I'm passing either an 'entry' or 'category' element into. 

I'd like to know how to differentiate between the possible element types; This kinda of works:

public function getElementType($element) {
  if ( isset($element-&gt;group) ) {
    return = 'category';
  } else if (isset($element-&gt;section)) {
    return = 'entry';        
  }
}


However I can't help but feel this is unreliable and hacky. Is there a better way to check an elements elementType?
Having arrived here from a Google search while trying to do this in Twig rather than PHP, I thought it might help someone in future to leave an answer, even though it doesn't address your question directly:
{{ item is instance of('craft\\elements\\Entry') ? 'This element is an entry!' }}
{{ item is instance of('craft\\elements\\Asset') ? 'This is an asset!' }}
{{ item is instance of('craft\\elements\\Category') ? 'This is a category!' }}
{{ item is instance of('craft\\elements\\User') ? 'This is a user!' }}

I find this especially useful in, for example, internal keyword search results listings templates, where the elements that were found might be of different types and you want to take different actions depending on the types.