title: How do I use FastRoute?
body: <p>I'm attempting to use the <a href="https://github.com/nikic/FastRoute" rel="noreferrer">FastRoute</a> routing library and can't get the simple usage example to work.</p>
  
  <p>Here is the basic usage example found on the <a href="https://github.com/nikic/FastRoute#usage" rel="noreferrer">GitHub page</a>:</p>
  
  <pre><code>&lt;?php
  
  require '/path/to/vendor/autoload.php';
  
  $dispatcher = FastRoute\simpleDispatcher(function(FastRoute\RouteCollector $r) {
      $r-&gt;addRoute('GET', '/users', 'get_all_users_handler');
      // {id} must be a number (\d+)
      $r-&gt;addRoute('GET', '/user/{id:\d+}', 'get_user_handler');
      // The /{title} suffix is optional
      $r-&gt;addRoute('GET', '/articles/{id:\d+}[/{title}]', 'get_article_handler');
  });
  
  // Fetch method and URI from somewhere
  $httpMethod = $_SERVER['REQUEST_METHOD'];
  $uri = $_SERVER['REQUEST_URI'];
  
  // Strip query string (?foo=bar) and decode URI
  if (false !== $pos = strpos($uri, '?')) {
      $uri = substr($uri, 0, $pos);
  }
  $uri = rawurldecode($uri);
  
  $routeInfo = $dispatcher-&gt;dispatch($httpMethod, $uri);
  switch ($routeInfo[0]) {
      case FastRoute\Dispatcher::NOT_FOUND:
          // ... 404 Not Found
          break;
      case FastRoute\Dispatcher::METHOD_NOT_ALLOWED:
          $allowedMethods = $routeInfo[1];
          // ... 405 Method Not Allowed
          break;
      case FastRoute\Dispatcher::FOUND:
          $handler = $routeInfo[1];
          $vars = $routeInfo[2];
          // ... call $handler with $vars
          break;
  }
  </code></pre>
  
  <p>Where the comment reads "... call $handler with $vars", I've tried returning <code>call_user_func_array($handler, $vars)</code> but it doesn't work.</p>
  
  <p>I also thought that maybe it was the <em>.htaccess</em> file that was stopping it working, as the Github page doesn't have a <em>.htaccess</em> file example for the project. I'm using this:</p>
  
  <pre><code>RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . index.php [QSA,L]
  </code></pre>
  
  <p>I've also tried calling a route with a closure as the handler, like so:</p>
  
  <pre><code>$r-&gt;addRoute('GET', '/', function() {
      echo 'home';
  });
  </code></pre>