3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CommentBase { private int $userId; private string $text; public function __construct(int $userId, string $text) { $this->userId = $userId; $this->text = $text; } public function getId() : int { return $this->id; } public function getUserId() : int { return $this->userId; } public function getText() : string { return $this->text; } public function setText(string $text) { $this->text = $text; } } interface Entity { public function getId() : int; } class Comment extends CommentBase implements Entity { private int $id; public function __construct(int $id, int $userId, string $text) { $this->id = $id; parent::__construct($userId, $text); } public function getId() : int { return $this->id; } } class CommentRepository { private array $entities = []; public function create(CommentBase $comment): Comment { $id = $this->generateId(); $entities[$id] = new Comment($id, $comment->getUserId(), $comment->getText()); return $entities[$id]; } public function update(Comment $comment): Comment { $this->entities[$comment->getId()] = $comment; return $this->entities[$comment->getId()]; } private function generateId() : int { return random_int(1, 1000000); } } $repo = new CommentRepository; $comment = $repo->create(new CommentBase(11, 'Test comment')); $comment->setText("updated comment"); $comment = $repo->update($comment); var_dump($comment);
based on B1PQL

Shows result from various feature-branches currently under review from the php developers. Contact me to have additional branches featured.

Output for branch php-master
object(Comment)#3 (3) { ["id":"Comment":private]=> int(219326) ["userId":"CommentBase":private]=> int(11) ["text":"CommentBase":private]=> string(15) "updated comment" }
Output for branch php-master+opcache
object(Comment)#3 (3) { ["id":"Comment":private]=> int(274917) ["userId":"CommentBase":private]=> int(11) ["text":"CommentBase":private]=> string(15) "updated comment" }

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page