Fatal Error must be compatible

use Slim\Psr7\Response;
use Slim\Psr7\Request;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;

final class Language implements Middleware
{
public function process(Request $request, RequestHandler $handler): Response
{
}
}

Fatal error : Declaration of Language::process(Slim\Psr7\Request $request, Psr\Http\Server\RequestHandlerInterface $handler): Slim\Psr7\Response must be compatible with Psr\Http\Server\MiddlewareInterface::process(Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Server\RequestHandlerInterface $handler): Psr\Http\Message\ResponseInterface

I use:
“nyholm/psr7”: “^1.1”
“nyholm/psr7-server”: “^0.3”

You’re not returning a response

use Slim\Psr7\Response;
use Slim\Psr7\Request;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;

final class Language implements Middleware
{
    public function process(Request $request, RequestHandler $handler): Response
    {
        return $handler->handle($request);
    }
}

I think the namespaces and everything are OK…

I ommit the code, I return a response but, also with your return same problem appears.

Hang on… I’m trying to look at each in order…

Fatal error : Declaration of Language::process(Slim\Psr7\Request $request, Psr\Http\Server\RequestHandlerInterface $handler): Slim\Psr7\Response must be compatible with Psr\Http\Server\MiddlewareInterface::process(Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Server\RequestHandlerInterface $handler): Psr\Http\Message\ResponseInterface

So looking at each:

                           Language::process(Slim\Psr7\Request $request, 
Psr\Http\Server\MiddlewareInterface::process(Psr\Http\Message\ServerRequestInterface $request,
Psr\Http\Server\RequestHandlerInterface $handler): Slim\Psr7\Response
Psr\Http\Server\RequestHandlerInterface $handler): Psr\Http\Message\ResponseInterface

So it strikes me as the problem is either that Slim\Psr7\Request isn’t compatible with Psr\Http\Message\ServerRequestInterface, or Slim\Psr7\Response isn’t compatible with Psr\Http\Message\ResponseInterface

Looking at the latest version of Slim-Psr7's Request class, I see:

use Psr\Http\Message\ServerRequestInterface;
...
class Request extends Message implements ServerRequestInterface

So that’s good. Looking at the latest version of the Response class, I see:

use Psr\Http\Message\ResponseInterface;
...
class Response extends Message implements ResponseInterface

So that’s also good. So I wonder if there’s a problem in your handler, maybe? It looks compatible to me

Solved with:

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;

1 Like

Of course… :man_facepalming: Totally my bad