3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ClientController { private $collection; public function __construct($collection) { $this->collection = $collection; $this->validate(); } protected function validate() { foreach ($this->collection as $model) { $props = get_object_vars($model); foreach ($props as $key => $val) { $method = 'validate' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key))); $valid = $model->$method(); if (!$valid) { $model->addError($key); } } if (length($model->getErrors())) { $model->setValid(false); } } } public function getCollection() { return $this->collection; } } class ClientModel { private $name; private $cpf; private $birth_date; private $email; private static $is_valid = true; private static $errors = []; public function __construct($name, $cpf, $birth_date, $email) { $this->setName($name); $this->setCpf($cpf); $this->setBirthDate($birth_date); $this->setEmail($email); } public function getName() { return $this->name; } public function setName($name) { $this->name = $name; } public function validateName() { return (!empty($this->name) && !preg_match("/^[a-zA-Z'-]+$/", $this->name)); } public function getCpf() { return $this->cpf; } public function setCpf($cpf) { $this->cpf = $cpf; } public function validateCpf() { return (!empty($this->cpf) && ctype_digit($this->cpf)); } public function getBirthDate() { return $this->birth_date; } public function setBirthDate($birth_date) { $this->birth_date = $birth_date; } public function validateBirthDate() { return (!empty($this->birth_date) && preg_match("/^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$/", $this->birth_date)); } public function getEmail() { return $this->email; } public function setEmail($email) { $this->email = $email; } public function validateEmail() { return (filter_var($this->email, FILTER_VALIDATE_EMAIL)); } public function isValid() { return $this->is_valid; } public function setValid($valid) { $this->is_valid = $valid; } public function addError($field) { $this->errors[] = $field; } public function getErrors() { return $this->errors; } } class ClientCollection { private $_clients = []; public function add(ClientModel $client) { $this->_clients[] = $client; end($this->_clients); return key($this->_clients); } public function get($key) { if (isset($this->_clients[$key])) { return $this->_clients[$key]; } else { throw new Exception("Client does not exist"); } } public function delete($key) { if (isset($this->_clients[$key])) { unset($this->_clients[$key]); } else { throw new Exception("Client does not exist"); } } } $clients = array( array("name" => "Hubert Adams", "cpf" => "86383860011", "birth_date" => "20/07/2015", "email" => "carlee_fadel@block.name"), array("name" => "Isabelle Mann", "cpf" => "58958058684", "birth_date" => "27/07/2015", "email" => "dortha.pacocha@ebert.biz"), array("name" => "Jayda Reichert", "cpf" => "01075384664", "birth_date" => "24/07/2015", "email" => "kaylie@stehrgaylord.biz"), array("name" => "Brionna Reinger", "cpf" => "48991299636", "birth_date" => "22/07/2015", "email" => "ansley.orn@herzog.org"), array("name" => "Diego", "cpf" => "55483741684aaaa", "birth_date" => "", "email" => "raoul mills com") ); $collection = new ClientCollection(); foreach ($clients as $client) { $model = new ClientModel($client['name'], $client['cpf'], $client['birth_date'], $client['email']); $collection->add($model); } $ctrl = new ClientController($collection); var_dump($ctrl->getCollection());

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)
8.3.60.0070.01416.75
8.3.50.0180.00321.02
8.3.40.0150.00018.82
8.3.30.0110.00419.02
8.3.20.0030.00520.13
8.3.10.0050.00323.48
8.3.00.0050.00317.63
8.2.180.0080.01518.42
8.2.170.0110.00622.96
8.2.160.0110.00320.52
8.2.150.0030.00624.18
8.2.140.0000.00824.66
8.2.130.0070.00026.16
8.2.120.0040.00422.25
8.2.110.0070.00321.05
8.2.100.0060.00617.86
8.2.90.0050.00319.40
8.2.80.0060.00317.97
8.2.70.0050.00317.63
8.2.60.0060.00318.05
8.2.50.0060.00318.10
8.2.40.0030.00518.34
8.2.30.0050.00318.24
8.2.20.0000.00817.86
8.2.10.0070.00018.19
8.2.00.0000.00818.23
8.1.280.0060.00925.92
8.1.270.0120.00420.22
8.1.260.0050.00326.35
8.1.250.0070.00028.09
8.1.240.0030.00723.83
8.1.230.0090.00317.58
8.1.220.0050.00317.74
8.1.210.0000.00818.77
8.1.200.0030.00717.60
8.1.190.0000.00817.25
8.1.180.0000.00818.10
8.1.170.0030.00618.63
8.1.160.0040.00422.18
8.1.150.0000.00718.89
8.1.140.0030.00817.39
8.1.130.0050.00319.24
8.1.120.0070.00017.53
8.1.110.0040.00417.45
8.1.100.0000.00817.47
8.1.90.0000.00817.52
8.1.80.0050.00317.52
8.1.70.0000.00717.55
8.1.60.0040.00417.61
8.1.50.0050.00517.57
8.1.40.0030.00617.63
8.1.30.0040.00417.68
8.1.20.0000.00917.68
8.1.10.0030.00617.60
8.1.00.0050.00317.58
8.0.300.0000.00818.77
8.0.290.0040.00416.88
8.0.280.0000.00718.50
8.0.270.0000.00717.17
8.0.260.0030.00316.98
8.0.250.0030.00617.10
8.0.240.0050.00217.11
8.0.230.0000.00817.09
8.0.220.0000.00716.91
8.0.210.0070.00017.03
8.0.200.0030.00317.14
8.0.190.0050.00517.08
8.0.180.0050.00317.07
8.0.170.0050.00316.95
8.0.160.0040.00416.98
8.0.150.0040.00416.93
8.0.140.0040.00417.04
8.0.130.0000.00713.40
8.0.120.0000.01116.88
8.0.110.0040.00416.92
8.0.100.0040.00416.90
8.0.90.0040.00416.88
8.0.80.0070.01017.00
8.0.70.0050.00216.92
8.0.60.0000.00817.05
8.0.50.0000.00817.00
8.0.30.0140.00717.17
8.0.20.0110.00917.40
8.0.10.0080.00017.04
8.0.00.0130.00616.81
7.4.330.0030.00315.10
7.4.320.0030.00316.59
7.4.300.0030.00316.71
7.4.290.0040.00416.57
7.4.280.0030.00616.67
7.4.270.0030.00416.47
7.4.260.0070.00016.63
7.4.250.0000.00816.58
7.4.240.0000.00816.58
7.4.230.0030.00516.60
7.4.220.0130.01316.62
7.4.210.0070.01116.54
7.4.200.0070.00016.67
7.4.160.0130.00816.62
7.4.150.0090.00917.40
7.4.140.0080.01017.86
7.4.130.0140.00616.41
7.4.120.0090.00916.46
7.4.110.0160.00316.64
7.4.100.0100.01016.43
7.4.90.0170.00816.48
7.4.80.0080.01119.39
7.4.70.0170.00216.43
7.4.60.0110.00616.61
7.4.50.0030.00316.55
7.4.40.0070.01416.32
7.4.30.0110.00616.46
7.4.00.0090.00614.97
7.3.330.0030.00313.25
7.3.320.0050.00013.43
7.3.310.0040.00416.43
7.3.300.0070.00016.45
7.3.290.0080.00616.42
7.3.280.0090.01216.41
7.3.270.0120.00917.40
7.3.260.0070.01016.41
7.3.250.0130.00916.56
7.3.240.0130.00616.42
7.3.230.0080.01616.67
7.3.210.0140.00416.41
7.3.200.0090.00919.39
7.3.190.0130.00316.46
7.3.180.0110.00816.73
7.3.170.0060.01216.55
7.3.160.0090.00816.68
7.3.120.0100.00314.95
7.3.110.0030.01414.88
7.3.100.0040.01515.19
7.3.90.0030.01414.96
7.3.80.0060.01314.94
7.3.70.0090.00914.92
7.3.60.0030.01415.09
7.3.50.0060.00614.92
7.3.40.0060.00915.04
7.3.30.0070.01014.91
7.3.20.0070.00316.81
7.3.10.0100.00516.80
7.3.00.0080.00916.53
7.2.330.0140.00516.51
7.2.320.0130.00716.73
7.2.310.0140.01316.54
7.2.300.0120.01216.53
7.2.290.0090.00916.85
7.2.250.0040.01515.28
7.2.240.0060.01215.35
7.2.230.0090.00914.78
7.2.220.0030.00714.86
7.2.210.0060.01014.96
7.2.200.0030.01315.12
7.2.190.0130.00315.13
7.2.180.0060.00614.90
7.2.170.0090.00614.77
7.2.130.0070.00716.55
7.2.120.0120.00416.68
7.2.110.0090.00416.41
7.2.100.0120.00816.86
7.2.90.0150.00317.03
7.2.80.0210.00316.83
7.2.70.0100.01016.69
7.2.60.0130.00716.82
7.2.50.0120.00616.71
7.2.40.0190.00316.55
7.2.30.0050.00716.67
7.2.20.0070.01416.39
7.2.10.0170.00016.80
7.2.00.0070.00818.18
7.1.330.0060.01015.81
7.1.320.0040.01216.10
7.1.310.0040.01415.93
7.1.300.0110.00315.68
7.1.290.0000.01415.76
7.1.280.0040.00815.78
7.1.270.0060.00915.80
7.1.260.0090.00615.95
7.1.250.0070.00715.59
7.1.200.0000.01515.76
7.1.100.0090.00318.00
7.1.70.0030.01016.87
7.1.60.0070.01519.59
7.1.50.0030.02216.91
7.1.00.0030.07322.35
7.0.200.0000.00916.84
7.0.60.0130.07720.11
7.0.50.0070.05017.83
7.0.40.0070.08720.14
7.0.30.0300.06320.13
7.0.20.0200.05020.13
7.0.10.0070.09020.28
7.0.00.0000.08720.18
5.6.280.0070.07320.82
5.6.210.0030.08320.70
5.6.200.0130.07318.21
5.6.190.0130.07720.61
5.6.180.0200.08720.47
5.6.170.0270.08020.55
5.6.160.0100.07320.54
5.6.150.0070.05318.29
5.6.140.0130.07018.25
5.6.130.0070.07718.22
5.6.120.0030.04021.04
5.6.110.0130.07721.15
5.6.100.0030.04321.17
5.6.90.0070.08321.01
5.6.80.0130.07320.41
5.5.350.0300.06720.38
5.5.340.0100.07718.02
5.5.330.0170.07320.31
5.5.320.0070.08320.32
5.5.310.0230.04720.30
5.5.300.0030.08318.11
5.5.290.0100.07318.02
5.5.280.0000.06020.91
5.5.270.0130.07320.68
5.5.260.0030.07020.83
5.5.250.0070.03720.60
5.5.240.0070.07320.39
5.4.450.0570.06019.39
5.4.440.0570.04719.48
5.4.430.0600.05319.20
5.4.420.0570.05719.38
5.4.410.0670.05719.18
5.4.400.0600.06019.23
5.4.390.0700.05319.13
5.4.380.0670.05718.90
5.4.370.0670.05319.02
5.4.360.0700.05719.05
5.4.350.0700.05319.14
5.4.340.0670.06018.90
5.4.320.0670.05719.14
5.4.310.0630.05719.08
5.4.300.0670.04319.07
5.4.290.0730.05019.05
5.4.280.0700.06019.18
5.4.270.0770.04318.88
5.4.260.0670.04319.10
5.4.250.0600.05319.24
5.4.240.0770.04718.90
5.4.230.0670.05719.03
5.4.220.0770.04719.23
5.4.210.0800.04019.11
5.4.200.0800.04716.84
5.4.190.0500.06019.07
5.4.180.0770.04719.09
5.4.170.0630.04719.27
5.4.160.0730.04719.07
5.4.150.0700.05318.87
5.4.140.0770.06016.31
5.4.130.0730.04316.30
5.4.120.0770.04716.50
5.4.110.0570.05316.50
5.4.100.0570.05316.30
5.4.90.0670.04316.61
5.4.80.0630.04716.66
5.4.70.0970.06316.66
5.4.60.0730.04716.32
5.4.50.0700.04716.27
5.4.40.0630.04716.27
5.4.30.0700.05716.26
5.4.20.0600.05316.39
5.4.10.0630.04316.35
5.4.00.0600.04315.82
5.3.290.0570.05714.59
5.3.280.0600.05014.50
5.3.270.0730.06314.79
5.3.260.0700.05314.66
5.3.250.0600.06314.51
5.3.240.0700.05314.60
5.3.230.0600.05714.53
5.3.220.0500.06014.43
5.3.210.0770.05014.50
5.3.200.0670.05314.61
5.3.190.0770.04314.43
5.3.180.0630.05314.47
5.3.170.0730.04714.64
5.3.160.0730.04714.55
5.3.150.0570.05314.49
5.3.140.0800.04314.52
5.3.130.0570.06014.72
5.3.120.0770.05314.52
5.3.110.0500.06014.61
5.3.100.0600.05713.95
5.3.90.0630.04713.89
5.3.80.0500.05713.99
5.3.70.0730.06014.04
5.3.60.0900.04713.93
5.3.50.0500.05313.85
5.3.40.0630.05313.92
5.3.30.0770.03714.08
5.3.20.0700.04313.71
5.3.10.0670.04013.73
5.3.00.0470.06013.76
5.2.170.0570.03311.11
5.2.160.0670.03011.07
5.2.150.0500.05011.17
5.2.140.0570.03311.31
5.2.130.0470.04010.99
5.2.120.0530.04311.05
5.2.110.0600.03711.09
5.2.100.0470.05011.14
5.2.90.0530.04011.23
5.2.80.0570.03711.05
5.2.70.0570.04011.17
5.2.60.0600.03711.21
5.2.50.0600.03711.11
5.2.40.0670.04010.92
5.2.30.0570.04311.05
5.2.20.0470.04010.89
5.2.10.0400.04010.82
5.2.00.0300.04710.71
5.1.60.0100.03010.07
5.1.50.0030.03710.14
5.1.40.0030.0379.84
5.1.30.0070.03710.34
5.1.20.0200.04010.52
5.1.10.0170.03010.17
5.1.00.0100.03710.02
5.0.50.0100.0238.51
5.0.40.0070.0278.59
5.0.30.0100.0378.17
5.0.20.0000.0308.22
5.0.10.0030.0308.19
5.0.00.0170.0378.18
4.4.90.0000.0235.88
4.4.80.0000.0235.76
4.4.70.0030.0305.74
4.4.60.0000.0305.85
4.4.50.0030.0235.85
4.4.40.0100.0305.90
4.4.30.0030.0235.90
4.4.20.0030.0235.83
4.4.10.0130.0135.92
4.4.00.0070.0335.90
4.3.110.0000.0275.82
4.3.100.0070.0205.77
4.3.90.0070.0205.68
4.3.80.0000.0405.65
4.3.70.0170.0105.65
4.3.60.0130.0135.64
4.3.50.0000.0275.75
4.3.40.0030.0335.75
4.3.30.0070.0204.83
4.3.20.0070.0204.83
4.3.10.0000.0234.83
4.3.00.0070.0237.05

preferences:
40.35 ms | 401 KiB | 5 Q