public function OnInit() { $main = new MainFrame(); $main->Show(); $controller = new ControlFrame($main->getDemoNames()); $controller->Show(); $controller->setChangeHandler(function ($index) use($main) { $main->switchDemo($index); }); // Must be called after the handler is set $controller->setChoice(0); return true; }