question about blog tutorial authentication method


I’m having trouble understanding the logic of the authenticate method in this page

particularly the return statement

return $this->errorCode==self::ERROR_NONE;

why not do the return inside each if statements?

Also the return looks like an error, but it’s not, so how is it possible that for example, the user is null, then $this->errorCode=self::ERROR_USERNAME_INVALID was called, but after that, the code returned $this->errorCode=self::ERROR_NONE but was yet able to inform the user of an invalid entry and block the user from passing the login form?

 public function authenticate()






        else if(!$user->validatePassword($this->password))








        return $this->errorCode==self::ERROR_NONE;


it is not "return $this->errorCode=self::ERROR_NONE;"

but "return $this->errorCode==self::ERROR_NONE;"

notice double-equals sign. this code returns true if $this->errorCode equals ERROR_NONE (which means that there is no error) and false otherwise.

Wow, I didn’t notice that. Thanks. It makes more sense now.