Skip to content

Instantly share code, notes, and snippets.

@imjacobclark
Created March 31, 2014 21:33
Show Gist options
  • Save imjacobclark/9902869 to your computer and use it in GitHub Desktop.
Save imjacobclark/9902869 to your computer and use it in GitHub Desktop.
<?php
// Classes vs Objects
class User{
private $email;
private $password;
const MINCHARS = 8;
public function login(){
return "Logging in";
}
public function logout(){
return "Logging out";
}
public function setEmail($e){
if(filter_var($this->email, FILTER_VALIDATE_EMAIL) ){
throw new Exception("A none valid email was provided");
}
$this->email = $e;
}
public function getEmail(){
return $this->email;
}
public function setPassword($p){
if(!$this->validatePassword($p)){
throw new Exception('The password should be '.self::MINCHARS.' chars long');
}
$this->password = hash('sha256', $p);
}
public function getPassword(){
return $this->password;
}
private function validatePassword($p){
return strlen($p) < self::MINCHARS ? false : true;
}
}
$user = new User();
$user->setEmail("[email protected]");
$user->setPassword('helloworld');
echo $user->login();
echo $user->logout();
echo $user->getPassword();
var_dump($user);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment