- var_dump: documentation ( source)
<?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());