3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php declare (strict_types=1); final class Immutable { private $views; public function __construct(int $views) { $this->views = $views; } public function increaseViews(int $views): self { $this->views += $views; return new self($this->views); } public function getViews(): int { return $this->views; } } $imm = new Immutable(1); $imm->increaseViews(3); $imm->increaseViews(3); $imm->increaseViews(3); $imm->increaseViews(3); $imm->increaseViews(3); $imm->increaseViews(3); $imm->increaseViews(3); $imm->increaseViews(3); $imm->increaseViews(3); print $imm->getViews();
Output for 7.3.0alpha1
28