Useridentity::authenticate()


	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? ???

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.

Thank you. :)

So it’s essentially the same as: return true;

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.