Partial fix \XF::asVisitor does not set/reset \XF::language()


Well-known member
Affected version
In \XF::asVisitor the global language fetched via \XF::language() is not set/reset when the visitor changes. This may effect the language and importantly the timezone which needs to be loaded from the visitor entity.


Well-known member
This is noticable as \XF::language() !== \XF::app()->language(), and neither may have the expected timezone depending on the visitor

XF Bug Bot

XenForo bug fixer bot
Staff member
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.2).

Change log:
Provide an option to use the given user's language when calling \XF::asVisitor()
There may be a delay before changes are rolled out to the XenForo Community.


XenForo developer
Staff member
Note that this is handled via an additional argument to the asVisitor method to attempt to avoid any potential differences in behavior (it defaults to not changing the language/timezone). This was generally just something we expected to be handled outside of this method (which was primarily for ensuring the correct user was selected for things like permission checks, etc).

Also worth mentioning that generally speaking, we don't change method signatures in third point/stable releases because it can create compatibility issues with add-ons. The XF object is pretty much the one exception to that because there's zero expectation that its extended (and zero opportunity to within XF). There is one very-much-theoretical way you could do it, but I think it's reasonable to say that it's well outside the scope of what's expected.