3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ValidationError { private array $errors = []; public function addError(string $fieldName, string $error) { $this->errors[$fieldName][] = $error; } public function haveErrors() : bool { return 0 !== count($this->errors); } public function printErrors() : void { print_r($this->errors); } } class UserForm { public string $name; public int $age; public function __construct(string $name, int $age) { $this->name = $name; $this->age = $age; } } class User { private string $name; private int $age; private function __construct(string $name, int $age) { $this->name = $name; $this->age = $age; } public static function createFromForm(UserForm $form) : User|ValidationError { $result = static::validate([ 'name' => $form->name, 'age' => $form->age, ]); if ($result) { return $result; } return new User($form->name, $form->age); } private static function validate(array $data) : ?ValidationError { $validationError = new ValidationError; if (20 < mb_strlen($data['name'])) { $validationError->addError('name', 'Too long. 20 chars only.'); } if (false !== mb_strpos($data['name'], 'хуй')) { $validationError->addError('name', 'Sam ti hui.'); } if (0 === $data['age']) { $validationError->addError('age', 'Too young.'); } if ($validationError->haveErrors()) { return $validationError; } return null; } } $correctForm = new UserForm('Test', 11); $result = User::createFromForm($correctForm); if ($result instanceof ValidationError) { $result->printErrors(); } $incorrectForm = new UserForm('Ты хуй', 0); $result = User::createFromForm($incorrectForm); if ($result instanceof ValidationError) { $result->printErrors(); }

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.0170.00316.62
8.3.60.0110.01116.63
8.3.50.0110.00718.45
8.3.40.0040.01620.49
8.3.30.0110.00418.85
8.3.20.0070.00024.18
8.3.10.0000.00824.66
8.3.00.0050.00326.16
8.2.190.0100.01016.58
8.2.180.0120.00325.92
8.2.170.0100.01018.91
8.2.160.0070.01022.96
8.2.150.0050.00325.66
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0060.00319.54
8.2.110.0110.00020.52
8.2.100.0060.00319.03
8.1.280.0150.00025.92
8.1.270.0080.00023.99
8.1.260.0080.00026.35
8.1.250.0000.00728.09
8.1.240.0100.00318.56
8.1.230.0090.00018.61
7.4.100.0150.00616.29
7.4.90.0140.00316.55
7.4.80.0070.01116.29
7.4.70.0030.01916.34
7.4.60.0050.01616.16
7.4.50.0040.01316.38
7.4.40.0070.01016.20
7.4.30.0060.01316.32
7.4.20.0090.00916.16
7.4.10.0030.01616.45
7.4.00.0140.00616.33
7.3.220.0100.01016.20
7.3.210.0130.00416.11
7.3.200.0130.00316.34
7.3.190.0140.00316.09
7.3.180.0070.01716.30
7.3.170.0070.01116.41
7.3.160.0090.00916.25
7.3.150.0060.01316.05
7.3.140.0090.00916.32
7.3.130.0120.01216.07
7.3.120.0130.00716.37
7.3.110.0170.00316.18
7.3.100.0100.00716.33
7.3.90.0140.01016.27
7.3.80.0120.01216.31
7.3.70.0060.01816.24
7.3.60.0120.01216.27
7.3.50.0070.01116.11
7.3.40.0140.00316.13
7.3.30.0070.01016.20
7.3.20.0060.01218.01
7.3.10.0110.01118.03
7.3.00.0160.00618.11
7.2.330.0120.00816.43
7.2.320.0100.00716.40
7.2.310.0150.00916.30
7.2.300.0070.01116.39
7.2.290.0070.01116.30
7.2.280.0110.00716.15
7.2.270.0110.00716.32
7.2.260.0190.00716.47
7.2.250.0160.01016.14
7.2.240.0000.02216.45
7.2.230.0120.00616.18
7.2.220.0120.01216.29
7.2.210.0160.01016.40
7.2.200.0070.01516.38
7.2.190.0100.01616.46
7.2.180.0120.00816.29
7.2.170.0110.00716.11
7.2.160.0110.00716.18
7.2.150.0050.01418.17
7.2.140.0090.00918.06
7.2.130.0170.00718.31
7.2.120.0100.01318.27
7.2.110.0150.00918.09
7.2.100.0110.01418.16
7.2.90.0100.01018.20
7.2.80.0100.01418.29
7.2.70.0070.01718.26
7.2.60.0140.01018.18
7.2.50.0180.00718.07
7.2.40.0170.00818.25
7.2.30.0110.01418.12
7.2.20.0080.01218.32
7.2.10.0100.01018.26
7.2.00.0130.00618.16

preferences:
43.71 ms | 401 KiB | 5 Q