<?php class Container { private array $services; public function __construct() { $this->services = [ static fn() => doStuff($this), ]; } } $container = new Container; unset($container); var_dump(gc_status()); class Container2 { private array $services; public function __construct() { $this->services = [ static fn(self $self) => doStuff($self), ]; } public function build() { foreach ($this->services as $service) { $service($this); } } } $container = new Container2; unset($container); var_dump(gc_status());
You have javascript disabled. You will not be able to edit any code.