Using the $app variable within a function outside of a class

When adding a tab, how can I use app scope without using “global”?
I’m not in a class when adding it, so I can’t use AppScopeTrait…

$t1 = $tab->addTab('Main', function($tab) {
global $app; // want to get rid of that
$t1Form = \atk4\ui\Form::addTo($tab);  // add the tab
$t1Form->setModel(new BecontactContactDetailModel($app->db))->load($_GET['val']); // need $app here...

I got these suggestions, but THEY DON’T WORK (remember: I’m outside of a class):
instead of

$t1Form->setModel(new BecontactContactDetailModel($app->db))->load($_GET['val']);

maybe you can use just a class (and no need for $app anymore)


or if that don’t work, then you can always

use ($app) 

and then you do not need “global” (<- use does work in class context only)


how about

$tab->app ?