3v4l.org

run code in 300+ PHP versions simultaneously
<?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();

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).

VersionSystem time (s)User time (s)Memory (MiB)
5.4.240.0120.04312.41
5.4.230.0120.04612.40
5.4.220.0130.04412.40
5.4.210.0110.04112.40
5.4.200.0240.05812.40
5.4.190.0130.04212.39
5.4.180.0120.04212.39
5.4.170.0100.04512.40
5.4.160.0110.04312.40
5.4.150.0200.06612.39
5.4.140.0130.03812.08
5.4.130.0130.03912.07
5.4.120.0140.03612.03
5.4.110.0110.04812.02
5.4.100.0150.03812.03
5.4.90.0140.03912.03
5.4.80.0130.03812.02
5.4.70.0130.03712.02
5.4.60.0130.03612.02
5.4.50.0110.04212.02
5.4.40.0140.03512.01
5.4.30.0100.04012.01
5.4.20.0130.03812.00
5.4.10.0190.06212.01
5.4.00.0130.03911.50
5.3.280.0140.04512.71
5.3.270.0100.04512.72
5.3.260.0130.04112.72
5.3.250.0130.03912.72
5.3.240.0110.04112.72
5.3.230.0130.04512.71
5.3.220.0110.04312.68
5.3.210.0120.04712.68
5.3.200.0130.04312.68
5.3.190.0140.04712.68
5.3.180.0190.06912.67
5.3.170.0140.04612.67
5.3.160.0090.04512.67
5.3.150.0130.04212.67
5.3.140.0130.04212.66
5.3.130.0140.04312.66
5.3.120.0150.05312.66
5.3.110.0160.04412.66
5.3.100.0130.04312.13
5.3.90.0120.04012.10
5.3.80.0130.04112.09
5.3.70.0140.03812.09
5.3.60.0110.04212.08
5.3.50.0220.05312.02
5.3.40.0110.04812.02
5.3.30.0110.04311.98
5.3.20.0110.03911.76
5.3.10.0120.04111.72
5.3.00.0140.05811.71

preferences:
141.32 ms | 1394 KiB | 7 Q