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