I think the problem with your code is to call the variable that receives the Slim App() object $this. That is, from what I saw you did: $this = new \Slim\App();
when you should have called the $app variable or any other but less a reserved word like $this, example:
$app = new \Slim\App();
I did the test with the code below and it worked normally:
<?php
use \Slim\App;
require '../vendor/autoload.php';
// Create app
$app = new \Slim\App();
// Get container
$container = $app->getContainer();
$app->get('/', function ($request, $response) {
echo "Slim Framework";
});
$app->get('/hello/{name}', function ($request, $response, $args) {
return $response->withJson('Name: ' . $args['name']
);
});
$app->get('/hello', function ($request, $response){
echo "Ola";
});
$app->get('/{id}', function($request, $response, $args) {
return $response->withJson("Id: " . $args['id']);
});
$app->run();
Adjust your code as above or simply rename the $this variable and see if it solves your problem.