3v4l.org

run code in 300+ PHP versions simultaneously
<?php readonly class ValidAge { private const MINIMUM_AGE = 10; private function __construct(public int $age) {} public static function createFromInt(int $age): self|NotValidAge { if (self::MINIMUM_AGE >= $age) { return new NotValidAge($age, 'Too old'); } return new self($age); } } readonly class NotValidAge { public function __construct( public int $age, public string $error ) {} } class ValidateAge { public function __invoke(int $age): ValidAge|NotValidAge { return ValidAge::createFromInt($age); } } class User { public function __construct( public int $id, public ValidAge $age ) {} } $rawAge = 33; $age = (new ValidateAge)($rawAge); $user = new User(1, $age); var_dump($user); $wrongAge = 8; $notValidAge = (new ValidateAge)($wrongAge); $anotherUser = new User(1, $notValidAge); var_dump($anotherUser);

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.4.120.0090.01024.22
8.4.110.0120.00819.18
8.4.100.0140.00718.88
8.4.90.0130.00620.73
8.4.80.0070.00218.18
8.4.70.0120.00618.09
8.4.60.0110.01018.70
8.4.50.0150.00820.38
8.4.40.0130.00717.61
8.4.30.0030.01719.14
8.4.20.0130.00718.11
8.4.10.0030.00619.64
8.3.250.0110.00818.80
8.3.240.0110.00817.03
8.3.230.0100.01016.62
8.3.220.0140.00518.90
8.3.210.0030.00416.80
8.3.200.0020.00716.71
8.3.190.0050.00518.77
8.3.180.0120.00716.78
8.3.170.0110.00718.93
8.3.160.0060.00318.40
8.3.150.0120.00818.73
8.3.140.0000.00817.17
8.3.130.0030.01718.55
8.3.120.0030.00620.89
8.3.110.0030.00622.58
8.3.100.0040.00422.58
8.3.90.0090.00022.58
8.3.50.0040.00422.58
8.2.290.0110.00820.46
8.2.280.0090.01020.09
8.2.270.0070.01017.41
8.2.260.0000.00820.28
8.2.250.0090.00018.62
8.2.240.0060.00318.80
8.2.230.0120.00322.58
8.2.220.0090.00022.58
8.2.210.0030.00622.58
8.2.130.0150.00528.09
8.1.330.0080.00821.86
8.1.320.0090.00515.88
8.1.310.0030.01418.35
8.1.300.0140.00420.18

preferences:
26.01 ms | 403 KiB | 5 Q