php - Calling function with TRUE returns wrong thing -
i have function
//$hasher phpass object. public function gethash( $check ) { global $hasher; if ( $check == 'hash' ) { homecoming $hasher->hashpassword($this->password); } else if ( $check == 'check' ) { homecoming $hasher->checkpassword($this->password, $this->getdata('data')['password']); } else { homecoming 'f*** off'; } } when phone call get
$obj->gethash('hash') //gethash(): $2a$08$uof.ezlkji.......... $obj->gethash('check') //gethash(): 1 $obj->gethash('dsadaldas') //and else in brackets //gethash():f*** off $obj->gethash(true) //gethash(): $2a$08$3vnyngvsf... why calling method true homecoming same if had called 'hash' argument? missing here? tried switch() , still behaves same.
because string such hash evaluates true when utilize equality operator (==):
you utilize identical (===) operator instead:
if ( $check === 'hash' ) this ensures both value of variable , type same.
php
No comments:
Post a Comment