XF 2.0 fetching elements from sometimes empty finder results

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;
 
Top Bottom