Skip to content


Choose a tag to compare
@ondrejmirtes ondrejmirtes released this 04 Dec 00:15

This is a massive release! Check out the accompanying article on for an overview of the major new features.

PHPStan 0.12 is brought to you by Gábor Hojtsy (@gaborhojtsy):

PHPStan has already been tremendous help in our preparation for Drupal 9 across the whole Drupal ecosystem, as a backbone of drupal-check, Upgrade Status and drupalci deprecation testing. It allows us to find common patterns in deprecated API use, make critical tooling decisions and rally the community. Thank you!

Major new features

  • Generics (huge thanks to @arnaud-lb!) See this article for more details on what they can do for you and how to start using them.
  • New level 6 - checking for missing typehints in function and method parameters and in properties. Previous level 6 is now level 7 and previous level 7 is now level 8.
  • Integer range types (#2484), thanks @JanTvrdik!
  • PHAR distribution by default - phpstan/phpstan Composer package now consists of a single PHAR file, similarly to the role previously handled by phpstan-shim repository which is now obsoleted. PHPStan development now happens at
  • Detection of methods and functions with no side effects called on separate lines - level 4. Functions like sprintf() and methods like DateTimeImmutable::setTime() called without reading the returned value are now detected.
  • Support for class-string and class-string<T> pseudotypes (phpstan/phpstan-src@77eb141, phpstan/phpstan-src@6262320)
  • Subtractable types - subtract subtypes from their supertype to find errors in code. mixed, object and concrete class objects now understand if their subtype is being subtracted from them. So for example a prior check for null on mixed now makes PHPStan understand that the type does not contain null anymore. This is especially useful for parent and child classes. See examples.
  • Check missing return in functions, methods, and closures - levels 0 and 3 (phpstan/phpstan-src@b149f8e)
  • Check for unreachable statements - level 4 (phpstan/phpstan-src@83078fe)
  • Check: new static() is safe only with final constructor or in final class - level 0 (phpstan/phpstan-src@3ebf508)
  • Check too wide return types on functions, closures and private methods (phpstan/phpstan-src@178953d, phpstan/phpstan-src@9155530, 78e04aa)
  • Various yield and generators related checks (phpstan/phpstan-src@c952192, phpstan/phpstan-src@96c57c6, phpstan/phpstan-src@83e1163)
  • Detect invalid types and wrong variable names in @var annotation tag - level 2 (phpstan/phpstan-src@25101c4, phpstan/phpstan-src@42a8618, phpstan/phpstan-src@d17e459)
  • Wrong 3rd party PHPDocs can now be overriden with custom stub files. Create PHP stub files like this and register them in your phpstan.neon using stubFiles config option. This feature can also be used to make non-generic classes and interfaces generic. Only PHPDocs are read from those files right now, nothing else.

BC breaks

  • Resolving relative paths in NEON according to config file placement (0c17a5b)
    • This means you no longer have to use ugly %rootDir%/../../../ in paths, but can use a relative path which is resolved relatively to the config file placement. So if you have phpstan.neon in the root of your project, you can reference your src/Foo.php file simply by src/Foo.php, no matter what the current working directory in your CLI prompt is.
  • Unknown config parameters are reported as errors. This prevents typos.
  • Docker image is based on official PHP Alpine image. See README on how to enable PHP extensions.

BC breaks for extension developers

Improvements and bugfixes

Link to range of commits on GitHub. Everything that has been merged and fixed so far is included in this release.