Not a bug Unreachable code?

Liam W

in memoriam 1998-2020
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
 
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).
 
Back
Top Bottom