Slim4 : Why doesn't it work?

I went through the tutorial (http://www.slimframework.com/2019/04/25/slim-4.0.0-alpha-release.html) for V4 and following the steps to install and run a small application… but got stuck at the very 1st stage where it has been written…
composer require slim/slim “^4.0”
There is no stable version yet, so how will it work?
So, as composer suggested to chose 4.0.0-alpha/4.0.0-beta/4.x-dev, I chose 4.x-dev and that never exists. Then I tried 4.0.0-alpha (composer require slim/slim “^4.0.0-alpha”) and same got installed well and I install slim psr7 using composer require slim/psr7:dev-master which was flawless!
Then I tried s simple example (as given in the tutorial)
<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
use Slim\Middleware\ErrorMiddleware;
use Slim\Middleware\RoutingMiddleware;

require DIR . ‘/vendor/autoload.php’;

$app = AppFactory::create();

$app->get(’/’, function (Request $request, Response $response, $args) {

  • $response->getBody()->write(“Hello world!”);*
  • return $response;*
    });

$app->run();
Which ended up with error!
And this as well…
<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
use Slim\Middleware\ErrorMiddleware;
use Slim\Middleware\RoutingMiddleware;

require DIR . ‘/vendor/autoload.php’;

$app = AppFactory::create();

/*

    • The routing middleware should be added earlier than the ErrorMiddleware*
    • Otherwise exceptions thrown from it will not be handled by the middleware*
  • /
    $routeResolver = $app->getRouteResolver();
    $routingMiddleware = new RoutingMiddleware($routeResolver);
    $app->add($routingMiddleware);

/*

    • The constructor of ErrorMiddleware takes in 5 parameters*
    • @param CallableResolverInterface $callableResolver -> CallableResolver implementation of your choice*
    • @param ResponseFactoryInterface $responseFactory -> ResponseFactory implementation of your choice*
    • @param bool $displayErrorDetails -> Should be set to false in production*
    • @param bool $logErrors -> Parameter is passed to the default ErrorHandler*
    • @param bool $logErrorDetails -> Display error details in error log*
    • which can be replaced by a callable of your choice.*
    • Note: This middleware should be added last. It will not handle any exceptions/errors*
    • for middleware added after it.*
  • /
    $callableResolver = $app->getCallableResolver();
    $responseFactory = $app->getResponseFactory();
    $errorMiddleware = new ErrorMiddleware($callableResolver, $responseFactory, true, true, true);
    $app->add($errorMiddleware);

$app->get(’/’, function (Request $request, Response $response, $args) {

  • $response->getBody()->write(“Hello world!”);*
  • return $response;*
    });

$app->run();
The only difference was the formation of the error was good for eyes but not good for the understanding!
So, why someone will use Slim4 when the tutorial itself guides wrong installation?
Developer can’t execute a simple script even after fixing the installation by his own!
And very surprisingly, you people haven’t covered this error anywhere… :roll_eyes::roll_eyes::roll_eyes::roll_eyes:
Type: Slim\Exception\HttpNotFoundException

Code: 404

Message: Not found.

File: C:\xampp\htdocs\vinpro\slim\vendor\slim\slim\Slim\Middleware\RoutingMiddleware.php

Line: 82