XF 2.0 The purpose of if($this->user_id)

CMTV

Well-known member
Hi!

I wonder why some can...() methods do check existence of user ID and some do not in User entity class?

PHP:
public function canViewWarnings()
{
   return ($this->user_id && $this->hasPermission('general', 'viewWarning'));
}

PHP:
public function canViewMemberList()
{
   return $this->hasPermission('general', 'viewMemberList');
}

Which way of writing my custom can...() methods should I stick with?
 
If we check for a user ID then it usually indicates that it's a permission that doesn't make sense to a guest. So regardless of whether "Unregistered" has that permission, unregistered users won't pass the check.
 
Top Bottom