PHP code example of syntatis / phpstan-psr-11

1. Go to this page and download the library: Download syntatis/phpstan-psr-11 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

syntatis / phpstan-psr-11 example snippets


use Bar\Service;
use Psr\Container\ContainerInterface;

class Foo
{
    public function __construct(ContainerInterface $container)
    {
        $service = $container->get(Service::class); 

        // PHPStan cannot infer the type of `$service`.
        // Check the type of the service at runtime.
        if ($service instanceof Service) {
        }
    }
}

use Bar\Service;
use Psr\Container\ContainerInterface;

class Foo
{
    public function __construct(ContainerInterface $container)
    {
        $service = $container->get(Service::class);
        // PHPStan inferred the type `$service` as Bar\Service.
    }
}