php - CodeIgniter 3 Login Class Throws array_key_exists() expects parameter 2 to be array, null given -


our codeigniter 3 source code has auth class located in applications/libraries following function:

public function login($attempt) {     $ci = & get_instance();     $ci->load->model("users");      // store password entry     $password = $attempt["password"];      // user database     $user = $ci->users->get(array("screen_name" => $attempt["screen_name"]));      if (!array_key_exists("password", $user)) {         return null;     }      // validate password     $valid = crypt($password, $user["password"]) == $user["password"];     if ($valid) {         // remove password - user data stored in session          unset($user["password"]);          // if no photo uploaded, set default         if (!isset($user["photo"]) || $user["photo"] == null) {             $user["photo"] = "http://oururl/ourroute/assets/images/defaultavatar.png";         } else {             //$user["photo"] = "files/images/" . $user["photo"];         }         return $user;     } else {         return false;     } } 

at first, thought return value had changed false null however, error persists after changing return value. since neither null nor false return values alleviate situation, other approach should taken remedy error @ hand?

the problem because of line returning null, instead of array

$user = $ci->users->get(array("screen_name" => $attempt["screen_name"])); 

before pass $user array_key_exists() function, should verify database returned meaningful result.

that segment of code written such

if ($user == null || !array_key_exists("password", $user)) {     return null; } 

in doing so, wont pass null value array_key_exists


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -