How to avoid "Trying to get property of non-object" after checking for no results in CodeIgniter
19:11 28 Jul 2013

I am completing my login function for my application and I'm receiving the trying to get property of non object on a few lines. The first one is shown below that does a function call to the is_user_locked method using the object property lock_date inside the user_data object. I understand that this means that at this point their is no user_data to work with so it can not use the properties. I'm curious to know how should I account for this so that I don't abuse using too many nested if statements.

if (count($user_data) == 0) {
    $output = array(
        'content' => 'The user was not found in the database!',
        'title' => 'User Not Found'
    );
}

if ($this->is_user_locked($user_data->lock_date)) {
     $output = array(
         'content' => 'This user account is currently locked!',
         'title' => 'Account Locked');
}

Any ideas on why this could be?

php codeigniter