• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Not a bug Unreachable code?

Liam W

Well-known member
#1
In the library/XenForo/User.php file, this code is in the addUsergroupChange method:

PHP:
if (!$addGroups)
{
    return true;
}
(Lines 1510-1513)

A few lines below, there is this block:

PHP:
if (isset($newGroups[$key]) && !$addGroups)
{
        // already exists and we're removing the groups, so we can just remove the record
        return $this->removeUserGroupChange($userId, $key);
}
(Lines 1519-1523)

Surely the code in the second if statement will never run, as if it the statement were to pass, the first if statement would have run and therefore stopped the method?

Liam
 

Mike

XenForo developer
Staff member
#2
You're probably right that it's unreachable as the behavior may have changed over time. I would say that unreachable code isn't generally a bug though (especially when it's just down to one condition).