This is probably basic stuff, but I´m no trained developer so bear with me. 

My question is: How can I get a class in php "global" so I can initialize it outside a function call, but still use it inside?

This example shows what I want to achieve, but does apparently not work:

```
$view = new Smarty();

$view->debugging = false;
$view->caching = false;
$view->cache_lifetime = 1;
$view->setTemplateDir('../views/');

$app->get('/register', function (Request $request, Response $response) {    
    $param = $request->getParams();

    $view->assign('name', $param["name"]);
    $response = $view->display('index.html');

    return $response;
});

```

To get it to work I have to define it within the $app->get call. Then of course the $view->debugging etc also have to be set inside the $app->get call.

The purpose of this is to avoid having to initialize a new instance of $view for every call and get the default settings to be global.

Edit:
Maybe I was to quick asking the question here. After a google search I think I may found the solution. But using "global $view" inside the function I get access to the instance of the class. This is different from other languages where you set "public $variable = new class.function()" but there is probably a reason for it being so, and I can definitely see how this can be a advantage for security/performance etc. Is there any alternative way? What is the pro/cons?