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

XF 2.0 fetching elements from sometimes empty finder results

Chris D

XenForo developer
Staff member
#2
You don't need to use isset, but you do need to actually check whether you have a user object. If your code is focused around having a user then presumably the subsequent code isn't much use.
PHP:
$user = $finder->where('user_id', 1);
if (!$user)
{
    // throw an exception ? log an error ? return ?
    return;
}
$username = $user->username;