3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class Constraint { public function __construct(array $options = null) { $defaultOptions = $this->getDefaultOptions(); foreach ($this as $option => $value) { if (isset($defaultOptions[$option])) { $this->{$option} = $defaultOptions[$option]; } else { throw new Exception('Ошибочка'); } } if (null !== $options) { $vars = get_object_vars($this); foreach ($options as $option => $value) { if (isset($vars[$option])) { $this->{$option} = $value; } else { throw new Exception('Ошибочка 2'); } } } } abstract protected function getDefaultOptions(): array; } class Length extends Constraint { public $min = 1; public $max; public $minMessage; public $maxMessage; public function __construct(array $options = null) { parent::__construct($options); } protected function getDefaultOptions(): array { return [ 'min' => 2, 'max' => 50, 'minMessage' => 'Значение меньше 2 символов', 'maxMessage' => 'Значение больше 50 символов' ]; } } interface ValidatorInterface { public function validate($value, Constraint $constraint): ?string; } class LengthValidator implements ValidatorInterface { public function validate($value, Constraint $constraint): ?string { if (!$constraint instanceof Length) { throw new Exception(); } $length = mb_strlen(trim($value)); if ($length < $constraint->min) { return $constraint->minMessage; } elseif ($length > $constraint->max) { return $constraint->maxMessage; } return null; } } $length = new Length([ 'min' => 3, 'max' => 50 ]); $lengthValidator = new LengthValidator(); $result = $lengthValidator->validate('Ян', $length); var_dump($result);

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.0150.00618.31
8.3.50.0140.00718.17
8.3.40.0140.00718.90
8.3.30.0070.00718.63
8.3.20.0050.00320.80
8.3.10.0080.00023.45
8.3.00.0040.00422.39
8.2.180.0100.00716.63
8.2.170.0060.01222.96
8.2.160.0100.00322.08
8.2.150.0030.00524.18
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0030.00519.50
8.2.110.0030.00722.21
8.2.100.0040.00817.59
8.2.90.0040.00418.28
8.2.80.0000.00817.97
8.2.70.0060.00318.03
8.2.60.0040.00418.16
8.2.50.0040.00418.10
8.2.40.0050.00319.14
8.2.30.0070.00419.32
8.2.20.0050.00218.25
8.2.10.0040.00419.33
8.2.00.0040.00418.25
8.1.280.0110.00425.92
8.1.270.0060.00320.73
8.1.260.0000.00826.35
8.1.250.0070.00028.09
8.1.240.0060.00323.94
8.1.230.0080.00321.04
8.1.220.0040.00417.78
8.1.210.0060.00319.04
8.1.200.0040.00417.36
8.1.190.0080.00017.35
8.1.180.0000.00818.10
8.1.170.0050.00318.64
8.1.160.0000.00718.87
8.1.150.0000.00718.88
8.1.140.0080.00020.29
8.1.130.0030.00320.30
8.1.120.0030.00717.51
8.1.110.0030.00717.44
8.1.100.0000.00817.38
8.1.90.0040.00417.39
8.1.80.0040.00417.42
8.1.70.0000.00717.45
8.1.60.0080.00317.50
8.1.50.0030.00517.65
8.1.40.0060.00317.64
8.1.30.0040.00417.64
8.1.20.0110.00017.71
8.1.10.0040.00417.71
8.1.00.0030.00617.54
8.0.300.0040.00420.03
8.0.290.0000.01016.63
8.0.280.0030.00518.53
8.0.270.0000.00716.96
8.0.260.0070.00021.93
8.0.250.0030.00517.08
8.0.240.0030.00617.12
8.0.230.0000.00717.13
8.0.220.0050.00516.92
8.0.210.0030.00616.94
8.0.200.0000.00716.99
8.0.190.0030.00517.10
8.0.180.0040.00417.03
8.0.170.0080.00317.08
8.0.160.0000.00717.14
8.0.150.0040.00416.94
8.0.140.0050.00317.03
8.0.130.0000.00513.48
8.0.120.0030.00517.02
8.0.110.0040.00416.95
8.0.100.0000.00716.93
8.0.90.0040.00417.14
8.0.80.0030.01417.04
8.0.70.0040.00416.84
8.0.60.0000.00817.07
8.0.50.0000.00717.04
8.0.30.0120.00817.22
8.0.20.0100.01017.40
8.0.10.0070.00017.22
8.0.00.0090.01116.91
7.4.330.0030.00315.55
7.4.320.0030.00316.43
7.4.300.0040.00416.61
7.4.290.0060.00316.63
7.4.280.0000.00816.62
7.4.270.0070.00016.57
7.4.260.0030.00316.61
7.4.250.0070.00016.64
7.4.240.0000.00716.48
7.4.230.0000.00716.33
7.4.220.0040.00416.38
7.4.210.0040.01016.49
7.4.200.0070.00016.71
7.4.160.0100.00616.54
7.4.140.0140.01017.86
7.4.130.0130.00616.66
7.4.120.0150.00616.48
7.4.110.0060.01116.59
7.4.100.0130.00416.47
7.4.90.0130.00316.53
7.4.80.0150.00919.39
7.4.70.0040.01716.46
7.4.60.0120.00416.58
7.4.50.0060.00916.63
7.4.40.0130.00316.49
7.4.00.0120.00314.77
7.3.330.0000.00513.20
7.3.320.0030.00313.34
7.3.310.0060.00316.29
7.3.300.0030.00316.39
7.3.290.0030.00316.44
7.3.280.0040.01216.32
7.3.260.0070.01316.51
7.3.240.0110.00816.42
7.3.230.0070.01016.43
7.3.210.0120.00616.64
7.3.200.0140.01216.26
7.3.190.0040.01216.69
7.3.180.0160.00016.59
7.3.170.0070.01316.50
7.3.160.0190.00316.67
7.3.30.0070.00714.67
7.3.20.0110.00814.65
7.3.10.1630.00314.66
7.3.00.0140.00314.93
7.2.330.0100.00716.74
7.2.320.0070.01216.71
7.2.310.0100.00616.79
7.2.300.0070.01016.59
7.2.290.0090.01316.61
7.2.160.0060.01515.18
7.2.150.0400.00315.20
7.2.140.0290.00714.99
7.2.130.1720.01015.12
7.2.120.0880.01315.17
7.2.110.0910.00715.16
7.2.100.0170.01015.20
7.2.90.0110.00615.21
7.2.80.1820.00314.96
7.2.70.1750.00315.26
7.2.60.1710.01015.05
7.2.50.2290.00015.18
7.2.40.1710.01014.87
7.2.30.1780.00315.11
7.2.20.1700.00315.07
7.2.10.1780.00714.94
7.2.00.1780.00715.00
7.1.270.0350.00614.13
7.1.260.0950.00314.17
7.1.250.0850.00714.14

preferences:
64.47 ms | 400 KiB | 5 Q