3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface ErrorProvider extends IteratorAggregate { public function add(string $error) : ErrorProvider; public function clear() : void; public function hasErrors() : bool; } interface ValidationSubject { public function setErrorProvider(ErrorProvider $errorProvider) : void; } class ConcreteErrorProvider implements ErrorProvider { private $errorList = []; public function add(string $errorMessage) : ErrorProvider { $this->errorList[] = $errorMessage; return $this; } public function clear() : void { $this->errorList = []; } public function hasErrors() : bool { return (boolean)$this->errorList; } public function __toString() : string { return implode("\n" , $this->errorList); } public function getIterator() : \Iterator { return new ArrayIterator($this->errorList); } } trait ValidationSubjectTrait { private $errorProvider; public function setErrorProvider(ErrorProvider $errorProvider) : void { $this->errorProvider = $errorProvider; } protected function setErrorMessage(string $errorMessage) : void { //Caso não haja um ErrorProvider, será lançada uma exception como de costume if (!$this->errorProvider instanceof ErrorProvider) { throw new \RuntimeException($errorMessage); } $this->errorProvider->add($errorMessage); } } class Person implements ValidationSubject { use ValidationSubjectTrait; /** método apenas para testes **/ public function setName($name) : void { $this->setErrorMessage("O nome não foi informado"); } /** método apenas para testes **/ public function setLastName($lastName) : void { $this->setErrorMessage("O sobrenome não foi informado"); } } try { $person = new Person(); $person->setName('Gabriel'); $person->setLastName('Heming'); } catch(Exception $exception) { echo $exception->getMessage(); } echo "\n --------------------- \n"; $errorProvider = new ConcreteErrorProvider(); $person = new Person(); $person->setErrorProvider($errorProvider); $person->setName('Gabriel'); $person->setLastName('Heming'); if ($errorProvider->hasErrors()) { echo $errorProvider; }

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.70.0090.00616.63
8.3.60.0090.00618.43
8.3.50.0070.01016.79
8.3.40.0040.01118.92
8.3.30.0030.01318.76
8.3.20.0040.00421.77
8.3.10.0040.00423.54
8.3.00.0040.00419.78
8.2.190.0070.00716.58
8.2.180.0060.00918.07
8.2.170.0120.00322.96
8.2.160.0100.01020.53
8.2.150.0070.00025.66
8.2.140.0050.00324.66
8.2.130.0000.00820.52
8.2.120.0000.00826.35
8.2.110.0050.00521.07
8.2.100.0080.00317.91
8.2.90.0000.00818.03
8.2.80.0050.00318.16
8.2.70.0080.00018.05
8.2.60.0000.00817.75
8.2.50.0040.00418.22
8.2.40.0050.00322.25
8.2.30.0040.00419.55
8.2.20.0000.00918.25
8.2.10.0000.00817.81
8.2.00.0000.00718.22
8.1.280.0120.00625.92
8.1.270.0000.00823.66
8.1.260.0000.00726.35
8.1.250.0040.00428.09
8.1.240.0070.00322.14
8.1.230.0030.00920.84
8.1.220.0040.00417.79
8.1.210.0000.00918.77
8.1.200.0040.00417.35
8.1.190.0000.00817.35
8.1.180.0030.00618.10
8.1.170.0050.00318.81
8.1.160.0000.00718.95
8.1.150.0040.00420.32
8.1.140.0040.00417.63
8.1.130.0030.00319.07
8.1.120.0000.00717.57
8.1.110.0040.00417.43
8.1.100.0030.00717.43
8.1.90.0000.01117.43
8.1.80.0000.00717.47
8.1.70.0040.00417.47
8.1.60.0000.00817.66
8.1.50.0060.00317.55
8.1.40.0040.00417.46
8.1.30.0040.00417.68
8.1.20.0000.00817.72
8.1.10.0090.00017.66
8.1.00.0060.00317.60
8.0.300.0040.00419.98
8.0.290.0000.00716.88
8.0.280.0070.00018.49
8.0.270.0030.00317.32
8.0.260.0030.00616.85
8.0.250.0000.00717.11
8.0.240.0030.00316.96
8.0.230.0000.00917.06
8.0.220.0030.00316.91
8.0.210.0070.00016.84
8.0.200.0040.00417.07
8.0.190.0000.00717.07
8.0.180.0040.00416.93
8.0.170.0090.00017.07
8.0.160.0000.00716.93
8.0.150.0040.00417.01
8.0.140.0100.00016.87
8.0.130.0000.00513.43
8.0.120.0040.00416.96
8.0.110.0070.00016.87
8.0.100.0040.00417.00
8.0.90.0000.00717.07
8.0.80.0150.00017.00
8.0.70.0040.00416.95
8.0.60.0040.00416.91
8.0.50.0050.00216.88
8.0.30.0080.01017.10
8.0.20.0160.00917.40
8.0.10.0050.00317.09
8.0.00.0060.01216.63
7.4.330.0050.00015.55
7.4.320.0070.00016.49
7.4.300.0000.00616.66
7.4.290.0030.00316.41
7.4.280.0030.00516.56
7.4.270.0000.00816.66
7.4.260.0040.00216.56
7.4.250.0030.00316.59
7.4.240.0000.00716.67
7.4.230.0070.00016.68
7.4.220.0040.00416.65
7.4.210.0120.00416.68
7.4.200.0000.00716.46
7.4.160.0110.00716.53
7.4.140.0080.01117.86
7.4.130.0060.01116.50
7.4.120.0100.01016.64
7.4.110.0090.00916.45
7.4.100.0030.01416.57
7.4.90.0100.00716.39
7.4.80.0120.00619.39
7.4.70.0080.00816.55
7.4.60.0100.00616.56
7.4.50.0070.01016.70
7.4.40.0130.00316.63
7.4.00.0030.01315.16
7.3.330.0050.00013.38
7.3.320.0030.00313.48
7.3.310.0030.00316.41
7.3.300.0050.00216.27
7.3.290.0070.01116.39
7.3.280.0080.00716.38
7.3.260.0120.00716.49
7.3.240.0080.01116.47
7.3.230.0060.01116.42
7.3.210.0130.00316.50
7.3.200.0040.01416.38
7.3.190.0030.01316.55
7.3.180.0070.01016.32
7.3.170.0110.00716.42
7.3.160.0120.00616.30
7.3.120.0030.01414.94
7.3.110.0060.01115.06
7.3.100.0050.01115.12
7.3.90.0060.00814.99
7.3.80.0080.00515.07
7.3.70.0070.00514.91
7.3.60.0050.00514.93
7.3.50.0070.00614.83
7.3.40.0110.00315.00
7.3.30.0030.01214.87
7.3.20.0050.01116.59
7.3.10.0060.00616.71
7.3.00.0040.00816.77
7.2.330.0040.01516.81
7.2.320.0080.01216.85
7.2.310.0090.01016.79
7.2.300.0060.01316.50
7.2.290.0150.00716.64
7.2.250.0160.00014.95
7.2.240.0050.01115.04
7.2.230.0060.00515.26
7.2.220.0050.00514.90
7.2.210.0120.00315.13
7.2.200.0040.01215.21
7.2.190.0000.01315.12
7.2.180.0090.00515.10
7.2.170.0060.00815.05
7.2.160.0030.01415.08
7.2.150.0060.00916.92
7.2.140.0000.01117.03
7.2.130.0090.00317.13
7.2.120.0070.00717.15
7.2.110.0030.01317.03
7.2.100.0050.00516.84
7.2.90.0030.01317.08
7.2.80.0000.01217.04
7.2.70.0070.01116.98
7.2.60.0100.00516.88
7.2.50.0040.00717.00
7.2.40.0060.01216.80
7.2.30.0200.01017.50
7.2.20.0130.00617.31
7.2.10.0150.00817.38
7.2.00.0090.01517.42
7.1.330.0070.00815.70
7.1.320.0070.00715.80
7.1.310.0040.00915.80
7.1.300.0050.00815.75
7.1.290.0040.00815.65
7.1.280.0030.01015.72
7.1.270.0080.00815.78
7.1.260.0020.01415.86
7.1.250.0080.00515.63
7.1.200.0030.01015.82
7.1.150.0150.01616.30
7.1.140.0190.01817.12
7.1.130.0180.01616.72
7.1.120.0200.01217.24
7.1.110.0190.01216.03
7.1.100.0590.01016.21
7.1.90.0210.00915.92
7.1.80.0130.01016.00
7.1.70.0170.00815.08
7.1.60.0330.02133.20
7.1.50.0380.01533.07
7.1.40.0290.01432.73
7.1.30.0360.01332.47
7.1.20.0350.01632.92
7.1.10.0150.01014.99
7.1.00.0380.01214.90

preferences:
44.93 ms | 401 KiB | 5 Q