3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $bar = 'A'; public function withNewBar($bar) { $obj = clone($this); $obj->bar = $bar; return $obj; } public function changeBarOnANewFoo($bar) { $obj = new Foo(); $obj->bar = $bar; return $obj; } public function changeBarOnAnotherFoo(Foo $obj, $bar) { $obj->bar = $bar; } public function bar() { return $this->bar; } } $one = new Foo(); $two = $one->withNewBar('B'); $three = $one->changeBarOnANewFoo('C'); $four = new Foo(); $one->changeBarOnAnotherFoo($four, 'D'); var_dump($one->bar() === 'A' ); var_dump($two->bar() === 'B' ); var_dump($three->bar() === 'C' ); var_dump($four->bar() === 'D' );
Output for git.master, git.master_jit, rfc.property-hooks
bool(true) bool(true) bool(true) bool(true)

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

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


preferences:
53.3 ms | 401 KiB | 8 Q