NotFoundException again

I’m running a fresh slim4 installation

exactly from user guide

on ubuntu php 7.4

my index.php it is the same from

https://www.slimframework.com/docs/v4/start/installation.html

step4 hello world

run with php built-in server no .htaccess
from …/public/
where index.php live

index
I get the eror when I ask for non existent route like

http://localhost:8888/foo

PHP Fatal error: Uncaught Slim\Exception\HttpNotFoundException:
Not found. in /var/www/html/slim4test/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php:76
Stack trace:
#0 /var/www/html/slim4test/vendor/slim/slim/Slim/Routing/RouteRunner.php(56): Slim\Middleware\RoutingMiddleware->performRouting()

#1 /var/www/html/slim4test/vendor/slim/slim/Slim/MiddlewareDispatcher.php(65): Slim\Routing\RouteRunner->handle()
#2 /var/www/html/slim4test/vendor/slim/slim/Slim/App.php(199): Slim\MiddlewareDispatcher->handle()
#3 /var/www/html/slim4test/vendor/slim/slim/Slim/App.php(183): Slim\App->handle() #4 /var/www/html/slim4test/public/index.php(16): Slim\App->run()
#5 {main}
thrown in /var/www/html/slim4test/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php on line 76
#5 {main}

I tried to require the file
require *require "/var/www/html/slim4test/vendor/slim/slim/Slim/Exception/HttpNotFoundException.php;

and get the error

PHP Fatal error: Uncaught Error: Interface 'Psr\Http\Server\MiddlewareInterface' not found in /var/www/html/slim4test/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php:25 #0 /var/www/html/slim4test/public/index.php(2): require() #1 {main} thrown in /var/www/html/slim4test/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php on line 25

it seems to me a problem withy namespaces - path

Make sure you have defined a route for the GET /foo path.

<?php

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Factory\AppFactory;

require __DIR__ . '/../vendor/autoload.php';

$app = AppFactory::create();

$app->get('/foo', function (ServerRequestInterface $request, ResponseInterface $response) {
    $response->getBody()->write('Foo');

    return $response;
});

// ...

$app->run();

Then, open a new console and start the built-in development server using this command:

php -S localhost:8888 -t public/

Then open: http://localhost:8888/foo

@odan
thx for your quick reply
I did this test to understand what happen in a basic Slim installation
when there is a non exisdting route
with php error display and reporting active that I consider a best practice
I also know I can setup Slim error handling
but in my opinion
PHP Fatal error: Uncaught Slim\Exception\HttpNotFoundException: i
I suppose this is a class not found error
should be classisfied as a bug
and I like to solve it
can you point me in the right direction ?

This is not a bug, because this “feature” allows you to define your own Error handler (middleware) by catching these type of (HTTP) exceptions.

If you want to use the default ErrorMiddleware, just add it like this:

// ...

$app->addRoutingMiddleware();

// This middleware should be added last
$app->addErrorMiddleware(true, true, true);

$app->run();

This should then give you a (pretty) error message instead of an exception.