You might consider to use WeakReference in your Container class. Don't forget to create the object into a variable and pass the variable to WeakReference::create() otherwise you going to ->get() null.
Consider as wrong solution, which returns null
<?php
public static function app() : App
{
if (!static::$app) {
static::$app = WeakReference::create(new App());
}
return static::$app->get();
}
?>
Consider as GOOD solution, which returns App instance
<?php
public static function app() : App
{
if (!static::$app) {
$app = new App();
static::$app = WeakReference::create($app);
}
return static::$app->get();
}
?>