<?php class Foo { public function __construct() { var_dump('created!'); } } class Bar { public function getFoo() { static $foo; return $foo ?? ($foo = new Foo); } } $bar = new Bar; var_dump($bar->getFoo(), $bar->getFoo(), $bar->getFoo());
You have javascript disabled. You will not be able to edit any code.