haosmark
(Haosmark)
February 4, 2013, 3:33am
1
public function authenticate()
{
$users=array(
// username => password
'demo'=>'demo',
'admin'=>'admin',
);
if(!isset($users[$this->username]))
$this->errorCode=self::ERROR_USERNAME_INVALID;
elseif($users[$this->username]!==$this->password)
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
$this->errorCode=self::ERROR_NONE;
return !$this->errorCode;
}
Can someone please explain return !$this->errorCode; to me?
I would understand if it stated return $this->errorCode; , but what does NOT do?
l.jurgs
(L Jurgs)
February 4, 2013, 5:01am
2
Ok, the ERROR_NONE constant equals 0, so it’s just inverting 0 (which in PHP is falsey) to true if ERROR_NONE. All the other constants there are integers equal to or greater than 1 (PHP truthy) so it inverts these to false.
haosmark
(Haosmark)
February 4, 2013, 5:27am
3
Thank you.
So it’s essentially the same as: return true;
mdomba
(Maurizio Domba Cerin)
February 4, 2013, 11:02am
4
Not exactly… to be clear… it’s the same only if there is no errors… if there is any error then it’s the same as return false.