3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Psuedo Model class Model { protected $comments; public function __construct() { $this->comments = new class { public function count() { $responses = [ 1, 2, 3, "Error: could not connect to database", 5 ]; $rand = rand(0, 4); if (is_string($responses[$rand])) { throw new Exception($responses[$rand]); } return $responses[$rand]; } }; } } // Log our errors and exceptions somewhere. class Logger { public static function log(string $log): void { echo $log; } } // Comment Count value object. final class CommentCount { private $count; public function __construct(int $count) { $this->count = $count; } public function getCount(): int { return $this->count; } } // Our core business logic to work out if we've had a lot of comments or not. class CommentWow { public function wow(CommentCount $commentCount): string { if ($commentCount->getCount() == 0) { return "Sad. :("; } if ($commentCount->getCount() > 0 && $commentCount->getCount() < 5) { return "Ok."; } if ($commentCount->getCount() >= 5) { return "Wow! :)"; } } } // Post model to retrieve comments count for a post. class Post extends Model { public function commentCount(): CommentCount { try { return new CommentCount($this->comments->count()); } catch (Exception $e) { Logger::log($e->getMessage()); return new CommentCount(0); } } } $post = new Post(); $commentCount = $post->commentCount(); $wow = new CommentWow(); var_dump($wow->wow($commentCount)); var_dump($wow->wow($commentCount)); var_dump($wow->wow($commentCount)); var_dump($wow->wow($commentCount)); var_dump($wow->wow($commentCount));

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)
7.4.50.0090.00916.27
7.4.40.0080.00816.09
7.4.30.0170.00316.37
7.4.20.0060.01516.26
7.4.10.0130.00616.38
7.4.00.0070.01016.34
7.3.170.0100.00616.51
7.3.160.0000.01716.35
7.3.150.0080.00816.02
7.3.140.0070.01116.35
7.3.130.0100.00616.33
7.3.120.0060.00916.28
7.3.110.0100.00716.23
7.3.100.0110.00616.38
7.3.90.0090.00916.48
7.3.80.0060.01016.64
7.3.70.0160.00016.41
7.3.60.0140.00316.28
7.3.50.0150.00316.39
7.3.40.0060.01216.35
7.3.30.0120.00316.52
7.3.20.0090.01516.43
7.3.10.0150.00616.37
7.3.00.0120.00616.49
7.2.290.0050.01316.84
7.2.280.0030.01316.74
7.2.270.0100.00716.87
7.2.260.0060.01116.78
7.2.250.0070.01016.73
7.2.240.0060.01116.55
7.2.230.0150.00316.56
7.2.220.0070.01016.85
7.2.210.0090.01316.70
7.2.200.0070.01016.75
7.2.190.0060.01216.81
7.2.180.0100.00716.55
7.2.170.0060.01116.58
7.2.160.0070.01716.64
7.2.150.0130.00816.75
7.2.140.0070.01116.71
7.2.130.0620.00016.64
7.2.120.0170.00516.65
7.2.110.0130.00816.63
7.2.100.0160.01016.86
7.2.90.0130.01316.84
7.2.80.0060.01316.68
7.2.70.0100.01016.68
7.2.60.0110.00816.69
7.2.50.0130.00616.73
7.2.40.0060.01216.71
7.2.30.0110.00816.89
7.2.20.0090.01516.62
7.2.10.0070.01616.83
7.2.00.0120.00916.61

preferences:
36.57 ms | 401 KiB | 5 Q