Slim 4.14.0 released

We are pleased to have released Slim 4.14.0. As a mature release, there aren’t many changes and all are minor and can be seen here.

Type hinting with template generics

This release introduces of template generic docblocks into Slim.

As Slim\App has a getContainer(): ?ContainerInterface method, the generics docblock enables you to specify what type is actually returned when this method is called. i.e. consider that you are using PHP-DI and have this code:

$container = $this->app->getContainer();
$entries = $container->getKnownEntryNames();

Psalm or PHPStan have no way of knowing that $container is an instance of DI\Container which has a getKnownEntryNames() method and so will complain.

To inform the static analyzer that we created Slim\App with PHP-DI, we change: /** @var \Slim\App $app */ to /** @var \Slim\App<DI\Container> $app */ and now PHPStan knows that getKnownEntryNames() is a valid method call on $container.

Update your type hints

For your codebase, if you type hint Slim\App instance variables using /** @var \Slim\App $app */, then you will need to change it to either:

  • /** @var \Slim\App<null> $app */ if you are not using a DI container, or
  • /** @var \Slim\App<\Psr\Container\ContainerInterface> $app */ if you are.

As noted above, you can also type hint to the concrete instance of the container you are using too.