After almost three years of further development, version 2.0 of the open source code analysis tool PHPStan is available. The update brings stricter type checking, revised memory management, a new list type, more accurate validation @var
-Low dependency on PHPDoc tags and caching.
Advertisement
Level 10 for strict type of examination
One of the most significant changes in the update is the introduction of Level 10, a new analysis level that performs an especially stringent type of checking, according to the announcement post. Its purpose is to improve the use of mixed
-Type PHP code explicitly mixed
-Identifies and reports values.
Level 10 encourages developers to provide more precise type information and ensures that code does not rely on indeterminate types, which could potentially lead to runtime errors.
New list types and optimized memory management
The second focus is on the introduction of a so-called list type, an array consisting of consecutive integer keys starting at 0 and having no gaps. According to the announcement post, List is one of the advanced types that can be represented in PHPDocs. The following example can be found in the release announcement:

/** @param list $listOfIntegers */
public function doFoo(array $listOfIntegers): void
{
}
Arrays should be easier for developers to work with due to the clear definition of specific data structures.
PHPStan 2.0 makes optimizations in memory management. According to their own information, the development team was able to reduce memory consumption by 70 percent, which clearly had a positive impact on the performance and speed of analysis of large code bases.
(Image: Antonkhrupinart/Shutterstock.com)
BetterCode() PHP 2024 will take place on November 21st. Online conference on PHP programming language helps developers to free their PHP applications from legacy issues and check them for best practices. Be prepared for upcoming innovations: PHP 8.4, PHPUnit 12 and much more! Tickets and more information Conference website provides,
Validation of PHPDoc tag @var
Also re-executes validation of updates @var
-PHPDoc tags, so-called annotations in PHP documentation comments, which specify the data type of a variable or expression to improve readability and facilitate type checking by developers and analysis tools. PHPStan 2.0 matches the base types of expressions assigned to these tags, which should help identify inconsistent and potentially incorrect type declarations. Additionally, PHPStan checks the correctness of the functions supplied with @phpstan-pure
Mark and report invalid symbols as errors.
Finally, PHPStan 2.0 reduces reliance on caching, which speeds up analysis and reduces storage requirements. The development aims to further increase the reliability and efficiency of code analysis.
More information about PHPStan 2.0 can be found in the announcement post On PHPStan Blog,
(MDO)
