3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Assert { private const UUID_LENGTH = 32; public static function validUuid(string $value) : string { if (strlen($value) !== static::UUID_LENGTH || false === ctype_xdigit($value)) { throw new \InvalidArgumentException('Wrong uuid format.'); } return __CLASS__; } public static function notEmptyString(string $value) : string { if ('' === $value) { throw new InvalidArgumentException('Value must not be empty.'); } return __CLASS__; } public static function notEmptyArray(array $value) : string { if (0 >= count($value)) { throw new InvalidArgumentException('Array must not be empty.'); } return __CLASS__; } } class Id { private string $value; public function __construct(?string $uuid = null) { $uuid = $uuid ?? $this->generateuuidV4(); Assert::validUuid($uuid); $this->value = $uuid; } public function __toString() : string { return $this->value; } public function isEqual(Id $id) : bool { return $this->value === (string)$id; } private function generateUuidV4() : string { return bin2hex(random_bytes(16)); } } interface Entity { public function getId() : Id; } class Comment implements Entity { private Id $id; private Id $userId; private string $text; public function __construct(Id $id, Id $userId, string $text) { Assert::notEmptyString($text); $this->id = $id; $this->userId = $userId; $this->text = $text; } public function getId() : Id { return $this->id; } public function getText() : string { return $this->text; } public function changeText(string $text) : void { $this->text = $text; } } class ModeratedComment extends Comment { private Comment $comment; public function __construct(Comment $comment) { $this->comment = $this->moderate($comment); } public function getId() : Id { return $this->comment->getId(); } public function getText() : string { return $this->comment->getText(); } public function changeText(string $text) : void { $this->comment->changeText($text); $this->comment = $this->moderate($this->comment); } private function moderate(Comment $comment) : Comment { $comment->changeText('Моча - сила'); return $comment; } } class Feed implements Entity { private Id $id; private Id $ownerId; private array $publishers; private array $comments; public function __construct( Id $id, Id $ownerId, array $publishers, array $comments = [] ) { Assert::notEmptyArray($publishers); $this->id = $id; $this->ownerId = $ownerId; $this->publishers = $publishers; $this->comments = $comments; } public function getId() : Id { return $this->id; } public function addComment(ModeratedComment $moderatedComment) { $this->comments[(string)$moderatedComment->getId()] = $moderatedComment; } } $feedId = new Id('3a90426a01e414d00f281ae92436f11d'); $feedOwnerId = new Id('da41d5f6b9ef685ddc3fc58f8f2b33f8'); $firstPublisherId = new Id('da41d5f6b9ef685ddc3fc58f8f2b33f8'); $secondPublisherId = new Id('76319d3a35d3ec306dc299d446ab46e6'); $publishers = [ (string)$firstPublisherId => $firstPublisherId, (string)$secondPublisherId => $secondPublisherId, ]; $feed = new Feed($feedId, $feedOwnerId, $publishers); $userId = new Id('da41d5f6b9ef685ddc3fc58f8f2b33f8'); $moderatedComment = new ModeratedComment(new Comment(new Id, $userId, 'Test comment')); $feed->addComment($moderatedComment); var_dump($feed);

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.10.0000.01616.86
7.4.00.0110.00616.66
7.3.130.0090.00616.41
7.3.120.0090.01416.23
7.3.110.0090.00516.15
7.3.100.0070.01116.20
7.3.90.0120.00316.05
7.3.80.0060.01616.10
7.3.70.0120.00616.20
7.3.60.0070.01016.14
7.3.50.0090.00616.24
7.3.40.0130.00316.12
7.3.30.0000.01816.20
7.3.20.0040.01416.11
7.3.10.0120.00316.07
7.3.00.0110.00416.17
7.2.260.0090.00616.48
7.2.250.0100.01016.52
7.2.240.0060.00916.25
7.2.230.0060.01216.37
7.2.220.0130.00316.32
7.2.210.0060.01516.19
7.2.200.0060.01116.26
7.2.190.0090.00616.36
7.2.180.0110.00716.34
7.2.170.0090.00616.31
7.2.160.0030.01316.20
7.2.150.0040.01616.47
7.2.140.0120.00616.18
7.2.130.0060.00916.10
7.2.120.0080.01216.18
7.2.110.0140.00716.47
7.2.100.0140.00716.32
7.2.90.0030.01316.25
7.2.80.0090.00616.18
7.2.70.0040.01216.50
7.2.60.0070.01016.41
7.2.50.0130.00316.33
7.2.40.0100.00716.56
7.2.30.0110.00716.53
7.2.20.0000.01716.40
7.2.10.0120.00316.36
7.2.00.0120.00416.36

preferences:
31.61 ms | 400 KiB | 5 Q