title: Slim Framework - cannot add route middleware
body: <p>I am new to Slim Framework and PHP. I cant get this to work, if I use a normal function and use "foo" as a parameter, it works, but doesnt work like this, even tho the documentation uses pretty much the same thing <a href="http://docs.slimframework.com/" rel="nofollow">http://docs.slimframework.com/</a></p>
  
  <pre><code>&lt;?php
      require 'Slim/Slim.php';
      session_start();
  
      \Slim\Slim::registerAutoloader();
      $app = new \Slim\Slim();
  
  
      $foo = function() {
         global $app;
          if(!isset($_SESSION["user_id"])) {
              $app-&gt;redirect("/redirecto/login");
          } else {
              echo "Authenticated";
          } 
      }
  
      $app-&gt;get("/", $foo, function() {
          global $app;
          $app-&gt;render('index.php');
      });
  
      $app-&gt;get("/login", function() use ($app) {
          $app-&gt;render("login.php");
      });
  
  ?&gt;
  </code></pre>
  
  <p>The error is</p>
  
  <pre><code>Parse error: syntax error, unexpected '$app' (T_VARIABLE) in C:\xampp\htdocs\redirecto\index.php on line 41 
  </code></pre>
  
  <p><em>(the $app->get("/", $foo, function() { line )</em></p>