3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $count; public function __construct() { $this->count = 1; } public function addCount() { $this->count++; } } class Bar { private $foo; public function __construct() { $this->foo = new Foo; } public function getFoo() { return $this->foo; } } $bar = new Bar; $foo = $bar->getFoo(); $foo->addCount(); var_dump($bar->getFoo()); var_dump($foo);

preferences:
29.95 ms | 402 KiB | 5 Q