@ 2014-01-17T15:34:33Z <?php
class UserModel {
public $name = null, $occupation = null, $email = null, $oldname = null, $oldoccupation = null, $oldemail = null, $me, $handler, $result;
public function __construct(){
}
public function create($fields = array()){
if(count($fields) == 3){
$this->name = $fields['name'];
$this->occupation = $fields['occupation'];
$this->email = $fields['email'];
}
}
public function _save(){
if($this->oldname == null && $this->oldoccupation == null && $this->oldemail == null){
$sql = "INSERT INTO users (name, occupation, email) VALUES ('".$this->name."', '".$this->occupation."', '".$this->email."')";
/*$this->result = $this->handler->prepare($sql);
/$this->result->execute(array(
':name'=>$this->name,
':occupation'=>$this->occupation,
':email'=>$this->email*/
echo $sql;
));
} else {
$sql = "UPDATE users SET name = '".$this->name."', occupation = '".$this->occupation."', email = '".$this->email."' WHERE name = '".$this->oldname."'";
/*$this->result = $this->handler->prepare($sql);
$this->result->execute(array(
':name'=>$this->name,
':occupation'=>$this->occupation,
':email'=>$this->email,
':oldname'=>$this->oldname
));*/
echo $sql;
}
}
public function name($given_name = null) {
if($this->name == null){
if($given_name != null){
$this->name = $given_name;
}
} else {
if($given_name != null){
$this->oldname = $this->name;
$this->name = $given_name;
}
}
return $this->name;
}
public function occupation($given_occupation = null) {
if($this->occupation == null){
if($given_occupation != null){
$this->occupation = $given_occupation;
}
} else {
if($given_occupation != null){
$this->oldoccupation = $this->occupation;
$this->occupation = $given_occupation;
}
}
return $this->occupation;
}
public function email($given_email = null){
$this->verifyEmail($given_email);
if($given_email != null){
// $this->oldemail = $this->email; // THIS LINE IS THE ISSUE
$this->email = $given_email;
}
return $this->email;
}
public function verifyEmail($givenemail = null){
if($givenemail == null){
$email = $this->email;
} else {
$email = $givenemail;
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw new Exception('Email not valid.');
die();
}
}
}
$user = new UserModel();
$user->create(array(
'name' => 'Luke',
'occupation' => 'Programmer',
'email' => 'luke@gmail.com'
));
$user->_save();
// $user->name('Jack');
// $user->occupation();
try {
$user->email('demo@example.co.za');
} catch (Exception $e) {
echo $e->getMessage();
}
$user->_save();
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.4.24 0.012 0.043 12.41 5.4.23 0.012 0.046 12.40 5.4.22 0.013 0.044 12.40 5.4.21 0.011 0.041 12.40 5.4.20 0.024 0.058 12.40 5.4.19 0.013 0.042 12.39 5.4.18 0.012 0.042 12.39 5.4.17 0.010 0.045 12.40 5.4.16 0.011 0.043 12.40 5.4.15 0.020 0.066 12.39 5.4.14 0.013 0.038 12.08 5.4.13 0.013 0.039 12.07 5.4.12 0.014 0.036 12.03 5.4.11 0.011 0.048 12.02 5.4.10 0.015 0.038 12.03 5.4.9 0.014 0.039 12.03 5.4.8 0.013 0.038 12.02 5.4.7 0.013 0.037 12.02 5.4.6 0.013 0.036 12.02 5.4.5 0.011 0.042 12.02 5.4.4 0.014 0.035 12.01 5.4.3 0.010 0.040 12.01 5.4.2 0.013 0.038 12.00 5.4.1 0.019 0.062 12.01 5.4.0 0.013 0.039 11.50 5.3.28 0.014 0.045 12.71 5.3.27 0.010 0.045 12.72 5.3.26 0.013 0.041 12.72 5.3.25 0.013 0.039 12.72 5.3.24 0.011 0.041 12.72 5.3.23 0.013 0.045 12.71 5.3.22 0.011 0.043 12.68 5.3.21 0.012 0.047 12.68 5.3.20 0.013 0.043 12.68 5.3.19 0.014 0.047 12.68 5.3.18 0.019 0.069 12.67 5.3.17 0.014 0.046 12.67 5.3.16 0.009 0.045 12.67 5.3.15 0.013 0.042 12.67 5.3.14 0.013 0.042 12.66 5.3.13 0.014 0.043 12.66 5.3.12 0.015 0.053 12.66 5.3.11 0.016 0.044 12.66 5.3.10 0.013 0.043 12.13 5.3.9 0.012 0.040 12.10 5.3.8 0.013 0.041 12.09 5.3.7 0.014 0.038 12.09 5.3.6 0.011 0.042 12.08 5.3.5 0.022 0.053 12.02 5.3.4 0.011 0.048 12.02 5.3.3 0.011 0.043 11.98 5.3.2 0.011 0.039 11.76 5.3.1 0.012 0.041 11.72 5.3.0 0.014 0.058 11.71
preferences:dark mode live preview
141.32 ms | 1394 KiB | 7 Q