3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php interface Counter { /** @return self */ public function count(); /** @return int */ public function getCount(); } class ImmutableCounter implements Counter { private $count; public function __construct($count = 0) { $this->count = (int) $count; } public function count() { echo $this->count; return new ImmutableCounter($this->count + 1); } public function getCount() { return $this->count; } } $counter = new ImmutableCounter(); $counter = $counter->count()->count()->count(); echo $counter->getCount();
based on AP62m
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.0
0123