How to check if current page is a group entity? Im using drupal 7 and group module

I am trying to run some code only if the current page is a group.

here is my code

&lt;?php
$arg = arg(0);
$arg1 = arg(1);
global $user;
if($arg ='group' &amp;&amp; is_numeric($arg1)) {
    $group = group_load($arg1);
    if($group-&gt;getMember($user-&gt;uid)) { 
       print ('user is member');  
    };
};
?&gt;


If this is placed on a group page it will print user is member if the current user is a member. If the current user isn't a member it will not show anything. Which is what it is supposed to do.

If I navigate to a none group page I get an error 'Error: Call to a member function getMember()',  but the if statement should prevent this?

How do I check if the current page is a group entity?

Thanks

Edit

I wanted to return true if a group page and user is a member of the group.
Using menu_get_object by Jaypan I used the code below to show. Im checking if page is group if so loading the group then checking if the user is a member of the group.

if (!empty(menu_get_object('group')))
   { 
   $group = group_load(arg(1));
   if($group-&gt;getMember($user-&gt;uid)) { 
       return TRUE;  
    }
}
You can get the object for the current page in Drupal 7 using menu_get_object().

if ($group == menu_get_object('group')) {
  // do something with $group
}