3v4l.org

run code in 300+ PHP versions simultaneously
<?php 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]; } }; } } class Logger { public static function log(string $log): void { echo $log; } } class CommentCount { private $count; public function __construct(int $count) { $this->count = $count; } public function getCount(): int { return $this->count; } } 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! :)"; } } } 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.0100.00716.23
7.4.40.0060.01216.55
7.4.30.0130.00816.37
7.4.20.0160.00616.34
7.4.10.0110.00716.60
7.4.00.0070.01116.68
7.3.170.0040.01316.38
7.3.160.0070.01016.64
7.3.150.0040.01816.35
7.3.140.0080.01216.29
7.3.130.0120.00916.41
7.3.120.0090.00616.26
7.3.110.0130.00316.39
7.3.100.0100.00616.41
7.3.90.0090.00916.60
7.3.80.0080.00916.36
7.3.70.0120.00616.34
7.3.60.0070.01016.43
7.3.50.0070.01016.36
7.3.40.0060.00916.30
7.3.30.0090.00916.39
7.3.20.0080.00816.39
7.3.10.0080.00816.51
7.3.00.0080.00816.53
7.2.290.0140.00716.82
7.2.280.0100.01016.41
7.2.270.0090.01016.33
7.2.260.0100.00716.64
7.2.250.0030.01416.54
7.2.240.0060.01016.60
7.2.230.0090.01116.79
7.2.220.0090.00916.69
7.2.210.0070.01016.54
7.2.200.0100.00716.38
7.2.190.0100.00716.51
7.2.180.0090.00916.51
7.2.170.0060.01016.65
7.2.160.0120.00616.52
7.2.150.0090.00816.62
7.2.140.0060.01016.71
7.2.130.0130.00316.71
7.2.120.0110.00616.76
7.2.110.0110.00516.71
7.2.100.0070.01016.59
7.2.90.0080.00816.75
7.2.80.0060.01216.71
7.2.70.0200.00916.74
7.2.60.0060.01216.76
7.2.50.0100.00716.71
7.2.40.0060.01216.92
7.2.30.0080.00816.84
7.2.20.0080.00916.55
7.2.10.0130.00316.57
7.2.00.0000.01716.51

preferences:
31.43 ms | 401 KiB | 5 Q