PHP Static Analysis Tool - discover bugs in your code without running it!

Overview

PHPStan - PHP Static Analysis Tool

PHPStan

Build Status Latest Stable Version Total Downloads License PHPStan Enabled


PHPStan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even before you write tests for the code. It moves PHP closer to compiled languages in the sense that the correctness of each line of the code can be checked before you run the actual line.

Read more about PHPStan in an introductory article Β»

Try out PHPStan on the on-line playground! Β»

Sponsors

TheCodingMachine     Private Packagist     Musement     Blackfire.io     Intracto     TicketSwap     ShipMonk     Togetter     RightCapital     ContentKing     ZOL

Documentation

All the documentation lives on the phpstan.org website:

PHPStan Pro

PHPStan Pro is a paid add-on on top of open-source PHPStan Static Analysis Tool with these premium features:

  • Web UI for browsing found errors, you can click and open your editor of choice on the offending line.
  • Continuous analysis (watch mode): scans changed files in the background, refreshes the UI automatically.
  • Interactive fixer: lets you choose the right fix for found errors 😊

Try it on PHPStan 0.12.45 or later by running it with the --pro option. You can create an account either by following the on-screen instructions, or by visiting account.phpstan.com.

After 30-day free trial period it costs 7 EUR for individuals monthly, 70 EUR for teams (up to 25 members). By paying for PHPStan Pro, you're supporting the development of open-source PHPStan.

You can read more about it on PHPStan's website.

Code of Conduct

This project adheres to a Contributor Code of Conduct. By participating in this project and its community, you are expected to uphold this code.

Contributing

Any contributions are welcome. PHPStan's source code open to pull requests lives at phpstan/phpstan-src.

Comments
  • Consider 1.0.0 for the next release number

    Consider 1.0.0 for the next release number

    Since PHPStan is becoming wildly popular really quick, and a lot of people rely on its stability, it is a good idea to start versioning new majors for anything that might slightly look like a BC break.

    (<insert reminder that major versions can be released anytime)

    opened by Ocramius 61
  • Do not execute tested code

    Do not execute tested code

    Currently PHPStan claims to be β€žPHP Static Analysis Toolβ€œ but this is actually a lie, because phpstan executes the tested code which makes using the tool quite dangerous.

    The correct solution is to use a library such as https://github.com/Roave/BetterReflection

    opened by JanTvrdik 59
  • Add comment ignore

    Add comment ignore

    Summary of a problem or a feature request

    Sometime we can have error like this:

     ------ ----------------------------------------------- 
      Line   tests/AppBundle/Entity/AbstractEntityTest.php  
     ------ ----------------------------------------------- 
      162    Call to an undefined method object::getId().   
     ------ ----------------------------------------------- 
    

    This case is a false positive (see #323) but can not be fixed yet.

    I can use ignoreErrors either because the error message is way to common.

    It would be great to be able to ignore phpstan analyse via code comment like this:

    $var = $this; // phpstan-ignore
    
    // phpstan-ignore-next-line
    $this->methodNotExists();
    

    What do you think?

    feature-request 
    opened by soullivaneuh 54
  • Large memory comsumption

    Large memory comsumption

    Large memory cunsumption in bitbucket pipeline

    I have 6GB RAM available for phpstan and I run phpstan with following command:

    vendor/bin/phpstan analyse -l 1 app -c app/config/phpstan.neon
    

    My phpstan.neon `parameters:

    parallel:
    	maximumNumberOfProcesses: 1
    	processTimeout: 3000.0`
    

    screen bitbucket

    Do somebody known why is 6GB RAM not enough? It is some way to decrease memory limit consumption?

    performance 
    opened by LuciferDevStar 52
  • "Using $this outside a class" in views templates

    In Yii2 templates, like this:

    <?php
    
    /* @var $this yii\web\View */
    /* @var $form yii\bootstrap\ActiveForm */
    /* @var $model App\Model\Foo */
    
    echo $this->title;
    

    PHPStan displays error about "Using $this outside a class".

    Is there a way to fix this without fully ignoring this error message? Like disabling rule for specified directory?

    feature-request 
    opened by Wirone 50
  • Intersection and generic types in phpDoc

    Intersection and generic types in phpDoc

    Playground

    New Features

    • intersection types in PHPDoc
      • Connection & MockInterface
    • generic syntax for array and iterable
      • array<ValueType>
      • array<KeyType, ValueType>
      • iterable<ValueType>
      • iterable<KeyType, ValueType>
    • complex array-of / iterable-of
      • (string | int)[]
    • any combination of the stuff above
      • ((Connection & MockInterface) | iterable<array<string | int>>)[]
    • rule for PHPDoc syntax validation
    • πŸ†• rule for checking that @param and @return annotations are compatible with native types

    BC Breaks (at least as of now)

    • dropped support for non-standard @var syntax, now it's reported as syntax error
      • /** @var $int int */
    • dropped support for non-standard PHPDoc syntax, now it's assumed to be plain comment
      • /* @var int $int */
    opened by JanTvrdik 42
  • False positives when using

    False positives when using "method_exists" condition on interfaces

    When variable is typed as interface and we use concrete implementation in code, sometimes there are valid calls to methods that doesn't exist in interface. For example when using Symfony\Component\HttpFoundation\Session\SessionInterface and want to use getFlashBag method, this will trigger error in PHPStan (level 2):

    /** @var \Symfony\Component\HttpFoundation\Session\SessionInterface $session */
    $session = $request->getSession();
    if ($session && method_exists($session, 'getFlashBag')) {
        $session->getFlashBag()->add('success', 'False positive detected!');
    }
    
    feature-request 
    opened by Wirone 41
  • Add support for conditional return type

    Add support for conditional return type

    Feature request

    This is a follow up of #3849 , and of https://github.com/doctrine/dbal/issues/4264

    I tried your suggestion, and it seems the root cause is conditional return types are not supported: https://phpstan.org/r/bdef5abe-d824-4311-aa6e-e0cce31ede92

    PHPDoc tag @phpstan-return has invalid value (($params is array{wrapperClass:mixed} ? T : Connection)): Unexpected token "$params", expected type at offset 82

    Cc @pkruithof @morozov

    feature-request 
    opened by greg0ire 40
  • PHPStan does not work with UNC paths on Windows

    PHPStan does not work with UNC paths on Windows

    Bug report

    PHPStan version: 0.12.32

    I am running a CentOS 7 instance using Windows Subsystem for Linux (WSL) on my Windows 10 PC. I accesses the CentOS 7 files using a UNC:

    \wsl$\CentOS7\my\files\here (which provides access to /my/files/here in the Linux file system)

    It seems that UNC paths are unsupported. See next section.

    Code snippet that reproduces the problem

    I tested by running the following at a command prompt in my C:\Users\me folder:

    phpstan analyze \\wsl$\CentOS7\my\files\here\blah.php

    Which provided the following error message:

    Path C:\Users\me\wsl$\CentOS7\my\files\here\blah.php does not exist

    I tested to ensure it does exist with our favorite built-in Windows command:

    dir \\wsl$\CentOS7\my\files\here\

    Which provided the list of files:

     Volume in drive \\wsl$\CentOS7 has no label.
     Volume Serial Number is 0000-0000
    
     Directory of \\wsl$\CentOS7\var\www\TDEV\import\shared
    
    07/01/2020  10:26 AM    <DIR>          .
    07/01/2020  10:26 AM    <DIR>          ..
    07/01/2020  10:51 AM             4,284 blah.php
                   1 File(s)         4,284 bytes
                   2 Dir(s)  107,505,917,952 bytes free
    

    Expected output

    I would have expected that phpstan would have happily analyzed blah.php just as it would have if the file was on a local drive such as C:.

    opened by jt-github 38
  • Jean85\PrettyVersions not found

    Jean85\PrettyVersions not found

    Both composer global install and phar fail with:

    phpstan.phar    
    PHP Fatal error:  Uncaught Error: Class 'PHPStanVendor\Jean85\PrettyVersions' not found in phar:///usr/local/bin/phpstan.phar/bin/phpstan:23
    Stack trace:
    #0 /usr/local/bin/phpstan.phar(4): require()
    #1 {main}
      thrown in phar:///usr/local/bin/phpstan.phar/bin/phpstan on line 23
    

    In addition, https://github.com/phpstan/phpstan/releases/tag/0.8.5 is missing phar.

    bug 
    opened by umpirsky 38
  • Warn about possible access to typed property before initialization

    Warn about possible access to typed property before initialization

    Feature request

    New typed properties (even nullable ones) in PHP 7.4 don't get null assigned as a default value, they are in a new uninitialized state. Trying to access an uninitialized property will raise a runtime error "Typed property Foo::$bar must not be accessed before initialization".

    Could be nice if code like this one could trigger an error about it.

    feature-request 
    opened by Lctrs 37
  • Narrow type of DOMNode to DOMElement when hasAttributes is true

    Narrow type of DOMNode to DOMElement when hasAttributes is true

    Feature request

    There are many DOM-related functions that return a DOMNode, but they may actually be returning a child of DOMNode. For example, DOMXPath::query returns a DOMNodeList<DOMNode>, but if the XPath expression can match element nodes, then the nodes in the list may have type DOMElement.

    According to https://www.php.net/manual/en/domnode.hasattributes.php, a DOMNode has to be a DOMElement if $node->hasAttributes() === true, so I thought it could be useful to add an assertion to the DOMNode::hasAttributes stub. I tried to make the following change to phpstan-src:

    diff --git stubs/dom.stub stubs/dom.stub
    index d2a5c575f..822e446dc 100644
    --- stubs/dom.stub
    +++ stubs/dom.stub
    @@ -30,6 +30,12 @@ class DOMDocument
     class DOMNode
     {
     
    +   /**
    +    * @phpstan-assert-if-true DOMElement $this
    +    * @return bool
    +    */
    +   public function hasAttributes() {}
    +
     }
    

    This raised an error upon testing:

    PHPStan\Command\AnalyseApplicationIntegrationTest::testExecuteOnAFile
    phpstan-src/tests/PHPStan/Command/data/file-without-errors.php
     ------ --------------------------------------------------------------------------------------------------------------------------------- 
      Line   phpstan-src/stubs/dom.stub                                                                                          
     ------ --------------------------------------------------------------------------------------------------------------------------------- 
      37     PHPDoc tag @phpstan-assert-if-true has invalid value (DOMElement $this): Unexpected token "\n\t * ", expected '->' at offset 48  
     ------ ---------------------------------------------------------------------------------------------------------------------------------
    

    I suspect that the second argument of @phpstan-assert-if-true must be a method, and cannot just be $this. However, it seems like this may be a useful feature as well: allow a method to narrow the type of the instance on which it's called. Should I submit that as a separate feature request, or is this already implemented by some other mechanism?

    The original request (narrowing DOMNode) is somewhat frivolous, since you can also narrow the type of the DOMNode by just checking $node instanceof DOMElement. If nothing is gained by enhancing DOMNode::hasAttributes, then I'm happy to close this issue. Thank you for your time!

    Did PHPStan help you today? Did it make you happy in any way?

    I use PHPStan almost every day to help modernize a 20 year old codebase as a labor of love. It is a gift to be able to use PHPStan to help with that!

    feature-request 
    opened by hemberger 2
  • Wrong error Using nullsafe method call on non-nullable type

    Wrong error Using nullsafe method call on non-nullable type

    Bug report

    PhpStan is reporting error Using nullsafe method call on non-nullable type UserObject. Use -> instead..

    But removing nullsafe operator leads to a fatal PHP error Call to a member function getUsername() on null.

    Code snippet that reproduces the problem

    https://phpstan.org/r/80f8009c-ab8a-4dde-825f-4bd5c9eea6e5

    Expected output

    Do not report any error.

    bug 
    opened by MatyCZ 0
  • Catching exception without capturing on PHP 7.4 is not allowed

    Catching exception without capturing on PHP 7.4 is not allowed

    Bug report

    Catching exceptions without capturing them was introduced in PHP 8. Still, PHPStan doesn't report the issue on PHP 7.4

    Code snippet that reproduces the problem

    https://phpstan.org/r/5d23db69-988e-4c4a-ba2a-934c3c06aac7

    Expected output

    Catching exceptions without capturing them to variables is only possible since PHP 8.0

    feature-request 
    opened by jurgenhaas 6
  • Inconsistent behavior regarding nullable string in null-coalescing operator.

    Inconsistent behavior regarding nullable string in null-coalescing operator.

    Bug report

    Hello, I have encountered a behavior in PHPStan which surprised me. See the attached snippet. I would expect that in both cases, PHPStan can correctly find out, that either $bar or $baz must be not null. And during evaluation of the null-coalescing operator, when the $bar is null, then the $baz must be not null. Therefore it should be valid to pass it as an argument to another function or use it as return value.

    When using as argument to other function, the PHPStan reports failure. When using as return value, PHPStan is OK with that.

    What am I doing wrong here? :)

    Code snippet that reproduces the problem

    https://phpstan.org/r/3b43ab30-2fbb-4347-96f5-39b29399cbe7

    Expected output

    I believe that the code above should return no PHPStan rule violations..

    Did PHPStan help you today? Did it make you happy in any way?

    Today, yesterday, the day before... But it usually makes me unhappy because it shows me how dumb I am! :D
    Many thanks you for your work to you, OndΕ™ej and the whole PHPStan community ;).

    bug 
    opened by Nemrtvej 0
  • array_key_first offset does not exits

    array_key_first offset does not exits

    Bug report

    I have an array of arrays and looping over it. I am then extracting the first array key with array_key_first. After that I am checking the key. In some cases I will do a continue inside the loop. But if all is fine, I try to get the value of the array with the given key. But here phpstan tells me that the offset does not exist.

    Code snippet that reproduces the problem

    https://phpstan.org/r/7bcc093c-65e8-4e01-aa35-7345c6cf7a0f

    Expected output

    I would expect, that all keys I am using to access the array are correct.

    Did PHPStan help you today? Did it make you happy in any way?

    I really love PHPStan and have much fun optimizing my code. :)

    feature-request 
    opened by Xirdion 0
  • Cannot assign new offset to array

    Cannot assign new offset to array

    Bug report

    As of PHPStan 1.9.5, I've been getting the following two errors when assinging values to an array

    Cannot assign new offset to array<int, array<string, string>>\|string.
    array<int, array<string, string>>\|string does not accept array<string, string>.
    

    Code snippet that reproduces the problem

    https://phpstan.org/r/454dceb7-086b-4f23-808d-b7af4c49dd48

    Expected output

    No issues are expected.

    Thanks for listening!

    opened by emodric 0
Releases(1.9.7)
  • 1.9.7(Jan 4, 2023)

    Bleeding edge πŸ”ͺ

    • Empty skipCheckGenericClasses (https://github.com/phpstan/phpstan-src/commit/28c2c79b16cac6ba6b01f1b4d211541dd49d8a77)

    If you want to see the shape of things to come and adopt bleeding edge features early, you can include this config file in your project's phpstan.neon:

    includes:
    	- vendor/phpstan/phpstan/conf/bleedingEdge.neon
    

    Of course, there are no backwards compatibility guarantees when you include this file. The behaviour and reported errors can change in minor versions with this file included. Learn more

    Improvements πŸ”§

    • UnionType::pickTypes overriden in BenevolentUnionType for a more benevolent behaviour (https://github.com/phpstan/phpstan-src/commit/480626ecb52d2e98cc28cee8a18dfb86112b7f8f)

    Bugfixes πŸ›

    • Fixed incorrect while loop logic (https://github.com/phpstan/phpstan-src/commit/091fcafb07ac0b3eb261285c049d9c0f214a535c), #8643
    • Fixed scenario with zero analysed files (https://github.com/phpstan/phpstan-src/commit/6debffdb5892f7fb311a60634ec9cda79b6e3154)

    Function signature fixes πŸ€–

    • min() and max() do not return false on PHP 8 (#2161), thanks @staabm!
    • Fix a few MongoDB definitions (#2140), thanks @UCIS!

    Internals πŸ”

    • Added missing namespaces in tests (#2156), thanks @staabm!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.27 MB)
    phpstan.phar.asc(833 bytes)
  • 1.9.6(Jan 3, 2023)

    Improvements πŸ”§

    • Show combined memory usage in parallel mode (#2027), #4683, thanks @janedbal!

    Bugfixes πŸ›

    • One-part encapsed string is correctly converted to string (https://github.com/phpstan/phpstan-src/commit/dc77608ee9ab22e352cd3df60ce2bc2d8d135abc), #8635
    • Conditional expressions - do not take conclusions about identical variable in assignment (https://github.com/phpstan/phpstan-src/commit/cde53d19e9b4edf81f4c469b7f2a2c3634004d86), #8625, #8621
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.27 MB)
    phpstan.phar.asc(833 bytes)
  • 1.9.5(Jan 2, 2023)

    Improvements πŸ”§

    • Improve constant string union handling for concat and encapsed string (#2057), thanks @schlndh!
    • PhpVersion: supportsDisjunctiveNormalForm (#2130), thanks @janedbal!
    • Constant scalar types might accept general type from the same family (#2131) - this moves some errors from earlier levels to level 7
    • Implement OversizedArrayBuilder to improve huge constant array performance (#2116), #8215, thanks @staabm!
    • Improve performance again by dumbing down nested arrays (#2077)
    • Result cache should not be invalidated by changes to editorUrl, editorUrlTitle and errorFormat parameters (#2136), thanks @bendavies!
    • Faster MutatingScope::shouldInvalidateExpression() (#2139), thanks @staabm!
    • Add ReturnStatementsNode::hasNativeReturnTypehint() (#2141), thanks @janedbal!
    • TypeNodeResolver - lowercase-string and non-empty-lowercase-string are known (https://github.com/phpstan/phpstan-src/commit/884ceb015c68e8c40a066732b4bc873bed568d38)

    Bugfixes πŸ›

    • OversizedArrayType contains at least 1 element (#2126), thanks @staabm!
    • Fix pathinfo($s, PATHINFO_ALL) return type (#2014), thanks @staabm!
    • Bump fidry/cpu-core-counter version (#2133), thanks @czukowski!
    • Fix MixedType::hasOffsetValueType() for subtracted types (#2135), #6705, thanks @herndlm!
    • Fix dumbed down arrays (#2137), #8004
    • Return type of parent::__set_state() method is only object (#2138), thanks @blankse!
    • Fix fatal error when autoloader opens directories (#2154), thanks @staabm!
    • Fix returntype for DateInterval::createFromDateString (#2038), thanks @verfriemelt-dot-org!
    • Fix hasSideEffects for AnnotationMethodReflection (#2155), thanks @VincentLanglet!
    • Fix constant-string handling in union-types (#2134), #8568, #8562, thanks @staabm!
    • IntersectionType - check if it's an oversized array and return benevolent union in getOffsetValueType (https://github.com/phpstan/phpstan-src/commit/80b5cdd3ecf173f0aaa7354d28537167905aec7c)

    Internals πŸ”

    • Use isArray, isConstantArray instead of instanceof in TypeCombinartor::union (#2118), thanks @rajyan!
    • Fix typo (#2127), thanks @rajyan!
    • AnalyserIntegrationTest - run with bleedingEdge (https://github.com/phpstan/phpstan-src/commit/db2de6f17469e9bc0d078e09c895d64a39fe14ca)
    • Refactor options handling in FilterVarDynamicReturnTypeExtension (#2120), thanks @herndlm!
    • Add Type::isScalar() (#2149), thanks @herndlm!
    • Removed unused fileName in FetchedNode (#2150), thanks @staabm!
    • Removed unused NodeList class (#2151), thanks @staabm!
    • Add namespace to bug-8573.php / fix GenericsIntegrationTest (#2147), thanks @herndlm!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.26 MB)
    phpstan.phar.asc(833 bytes)
  • 1.9.4(Dec 17, 2022)

    Improvements πŸ”§

    • Various performance optimizations from @staabm (#2098, #2099, #2100, #2101, #2103, #2104)
    • Resolve parameter types only when checkArgumentTypes=true (#2106), thanks @staabm!
    • Keep NeverType isExplicit flag in TypeCombinator::intersect() (#2112), thanks @staabm!
    • Keep NeverType isExplicit flag in InitializerExprTypeResolver (#2114), thanks @staabm!
    • Add TypeCombinator::removeFalsey() (#2003), thanks @axlon!
    • Option usePathConstantsAsConstantString (#2050), thanks @MartinMystikJonas!

    Bugfixes πŸ›

    • Fix native type on unset (#2107), #7805, thanks @rajyan!
    • Fix return type of array_search() with constant array type haystack (#1806), #3789, thanks @takaram!
    • parse_str() might return nested arrays by-ref (#1994), #8356, thanks @staabm!
    • Fix regression in for loop (https://github.com/phpstan/phpstan-src/commit/a8975b1800d6c5cb88a6af02e132b4e44e093fc3), #8520
    • Fix readonly properties bugs and infinite recursion (https://github.com/phpstan/phpstan-src/commit/a7fed03bbf1bef545c8afcbf6c906ac93b34c876), #8543
    • Fix internal error for dynamic properties defined on interface on PHP 8.2 (https://github.com/phpstan/phpstan-src/commit/4025209062e31619077197006ce44b5d60a9f2c1), #8537

    Internals πŸ”

    • Implement getConstantStrings() on Type (#1979), thanks @staabm!
    • Fix node PHPDoc type hints (#2053), thanks @herndlm!
    • Refactor FilterVarDynamicReturnTypeExtension to pass around Types instead of Args and the Scope (#2109), thanks @herndlm!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.23 MB)
    phpstan.phar.asc(833 bytes)
  • 1.9.3(Dec 13, 2022)

    Bleeding edge πŸ”ͺ

    • Fix invariance composition (#2054), thanks @jiripudil!

    If you want to see the shape of things to come and adopt bleeding edge features early, you can include this config file in your project's phpstan.neon:

    includes:
    	- vendor/phpstan/phpstan/conf/bleedingEdge.neon
    

    Of course, there are no backwards compatibility guarantees when you include this file. The behaviour and reported errors can change in minor versions with this file included. Learn more

    Improvements πŸ”§

    • TypeInferenceTestCase - do not allow files with no asserts (#1992), #8346, #8094, thanks @herndlm!
    • DateTimeZone::__construct throw type extension (#2034)
    • TableErrorFormatter: allow editor url title configuration (#2035), #7796, thanks @janedbal!
    • Various generics variance fixes (#2051, #2064), #3960, thanks @jiripudil!
    • Add deprecationRulesInstalled configuration (#2062), thanks @villfa!
      • To be used in phpstan-deprecation-rules and phpstan-phpunit extensions soon!
    • ArrayFilterRule should care about treatPhpDocTypesAsCertain (#2065), thanks @VincentLanglet!
    • Discover phpunit-bridge automatically (https://github.com/phpstan/phpstan-src/commit/c760b1f7a45c512cd34c91d8e078046dfdc453ba)
    • Performance optimizations:
      • Cache descriptions in ObjectType and UnionType (https://github.com/phpstan/phpstan-src/commit/da8413c493cbb9d800228f996836207e9598920c), #8499, #8497
      • Remove unnecessary file IO (#2069, #2094), thanks @staabm!
      • Reduce calls to Scope::getType(). Cheap checks first. (#2071), thanks @staabm!
      • Cache resolved phpdoc in ClassReflection (#2072), thanks @staabm!
      • Don't re-calculate node-key over and over again (#2073), thanks @staabm!
      • Improve the CPU core count detection (#2047), thanks @theofidry!
      • Optimize path related utils on windows (#2068), thanks @staabm!
      • Don't re-calculate node-key over and over again - part 2 (#2074), #8503, thanks @staabm!
      • Faster ConstantStringType->toArrayKey() (#2081), thanks @staabm!
      • Faster ConstantFloatType->isSuperTypeOf(ConstantFloatType) (#2080), thanks @staabm!
      • TypeSpecifier micro-optimization (https://github.com/phpstan/phpstan-src/commit/30e6d19496adb16b6bfd9be1cd1bf767f6ce8713)
      • Faster TrinaryLogic->lazyExtremeIdentity() (#2083), thanks @staabm!
      • Faster ConstantArrayType->isSuperTypeOf() (#2086), thanks @staabm!
      • Loops analysed in linear time instead of exponential time (#2088, #2091), #8503, #6265
      • Remove unnecessary method call to already known value (#2092), thanks @staabm!

    Bugfixes πŸ›

    • Improve conditionalExpressionTypes (#1950), #3677, #5623, #5401, #7292, #8212, thanks @rajyan!
    • Fix conditional variable types in global scope (#1995), thanks @rajyan!
    • Do not invalidate related expressions in ensureNonNullability (#2004), #8361, thanks @rajyan!
    • Improve create conditional expressions to handle all expressions (#2007), thanks @rajyan!
    • Improve conditional type resolving performance (#2030), #8397, #5805, thanks @rajyan!
    • Fix false positive of access to static private property of parent class (#1989), #8333, thanks @staabm!
    • Fix intersecting array shapes with different optional keys (#2002), #8373, thanks @rvanvelzen!
    • Support PHPDoc asserts on variadic parameters (#2009), #8389, thanks @rvanvelzen!
    • Fix @param-out on methods (#2028), #8421, thanks @staabm!
    • Do not set native type to mixed on annotation assignment (#2017), thanks @herndlm!
    • Consistently pass $nativeExpressionTypes in MutatingScope (#2021), thanks @herndlm!
    • Fix infinite loop when fully qualified callback is supplied (#2005), #8376, thanks @cs278!
    • Non-static method DOMDocument::loadHTML() can be called statically (#2042), #2759, thanks @staabm!
    • Fix FuzzyRelativePathHelper for directories ending in .php (https://github.com/phpstan/phpstan-src/commit/bff85e27cd486b7ea5c065575a71de66b83b1cf2), #8480

    Function signature fixes πŸ€–

    • ImagickPixel::getColor() normalized param accepts int instead of bool (#2020), thanks @blankse!
    • Declare more PDOStatement method types (#2096), thanks @staabm!

    Internals πŸ”

    • Fix non-working type assertions in NodeScopeResolverTest cases (#1992), thanks @herndlm!
    • Use ExpressionTypeHolders for conditional expression type (#1998), thanks @rajyan!
    • Simplify array collections in UnionTypeHelper (#1988), thanks @herndlm!
    • Avoid specifying scalar types and delete string casts (#1999), thanks @rajyan!
    • Add filename and line of the error of assertVariableCertainty (#2008), thanks @rajyan!
    • README: how to composer install (#2025), thanks @janedbal!
    • Group $expressionTypes and $nativeExpressionTypes in Scope creation methods (#2022), thanks @herndlm!
    • Use ExpressionTypeHolder when comparing conditionals (#2048), thanks @rajyan!
    • UnionType - carry information that it's normalized (https://github.com/phpstan/phpstan-src/commit/96e4443d94501012042cf6bd9f8d6b34af7fcfb6)
    • VerbosityLevel offers getLevelValue() (https://github.com/phpstan/phpstan-src/commit/4f7e20b6ffae103ac3de52e5da1ef77dbc0ba485)
    • Get rid of TypeTraverser in ArrayChunkFunctionReturnTypeExtension (#2082), thanks @herndlm!
    • Get rid of TypeTraverser in ArraySliceFunctionReturnTypeExtension (#2085), thanks @herndlm!
    • Get rid of TypeTraverser in ArrayReverseFunctionReturnTypeExtension (#2084), thanks @herndlm!
    • Get rid of TypeTraverser in StrSplitFunctionReturnTypeExtension (#2087), thanks @herndlm!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.22 MB)
    phpstan.phar.asc(833 bytes)
  • 1.9.2(Nov 10, 2022)

    Bugfixes πŸ›

    • Fix array and iterable type action methods on NeverType (#1968), #8277, thanks @herndlm!
    • Support 'HasMethodType' on StaticCall (#1969), #1267, thanks @staabm!
    • Addition operation on MixedType without ArrayType cannot result in ArrayType (#1949), thanks @staabm!
    • Remove DateInterval stub (#1974), thanks @VincentLanglet!
    • Fix invalidate static expressions in closures (#1983), #8292, thanks @rajyan!
    • Fix false positive of access to private property of parent class (#1953), #2435, thanks @tyabu12!
    • Fix unset on nested array (#1987), #8113, thanks @rvanvelzen!

    Function signature fixes πŸ€–

    • Update DateTimeZone::listAbbreviations signature (#1962), thanks @franmomu!
    • Making json_encode() always produce a non-empty-string, when successful (#1980), thanks @Slamdunk!
    • sodium_crypto_generichash* always produce a non-empty-string (#1981), thanks @Slamdunk!
    • sodium_crypto_sign* always produce non-empty-string (#1985), thanks @Slamdunk!

    Internals πŸ”

    • Implement isClassStringType() on Type (#1970), #6147, thanks @staabm!
    • Implement isInteger() on Type (#1971), thanks @staabm!
    • Implement isBoolean() on Type (#1973), thanks @staabm!
    • Implement isFloat() on Type (#1977), thanks @staabm!
    • Implement isNull() on Type (#1978), thanks @staabm!
    • Add Type::isVoid() (#1982), thanks @herndlm!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.18 MB)
    phpstan.phar.asc(833 bytes)
  • 1.9.1(Nov 4, 2022)

    Improvements πŸ”§

    • AccessoryArrayListType is part of BC promise (#1967), thanks @enumag!
    • Specify types from true/false asserts (#1957), thanks @rvanvelzen!
    • Support conditional types in phpdoc asserts (#1964), thanks @rvanvelzen!
    • Let casting object to string result in an error (#1948), thanks @rvanvelzen!
    • Add more support for checkBenevolentUnionTypes config (#1940), thanks @VincentLanglet!
    • Error on unknown parameter name in parameter conditional type (#1966), #8284, thanks @rvanvelzen!

    Bugfixes πŸ›

    • List type cast to array is still a list (#1958, #1959), #8280, thanks @rajyan!
    • Fix mt_rand return type (#1956), #8272, thanks @enumag!
    • strtr returns non-empty-string (#1963), thanks @staabm!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.15 MB)
    phpstan.phar.asc(833 bytes)
  • 1.9.0(Nov 3, 2022)

    Check out the article about this release!

    Major new features πŸš€

    • PHPDoc-based type narrowing with @phpstan-assert, @phpstan-assert-if-true, @phpstan-assert-if-false (#1317), #7110, #8186, thanks @rvanvelzen!
    • @phpstan-self-out/@phpstan-this-out support (#1799), thanks @rvanvelzen!
      • Can be used to change the type of the current object after calling a method on it. This is useful for generic mutable objects.
      • Documentation
    • @param-out support (#1804), #7231, #6871, #6186, #4372, #5785, thanks @staabm!
      • Can be used to specify type of function argument passed by reference
      • Documentation
    • Add extensible ClassReflection::getAllowedSubTypes() (#1477), thanks @jiripudil!
    • Add config parameter checkBenevolentUnionTypes to strictly check BenevolentUnionType (#1930), #8223, thanks @VincentLanglet!

    Bleeding edge πŸ”ͺ

    • Array list type (#1751), #3311, #8185, #6243, thanks @rvanvelzen!
      • Lists are arrays with sequential integer keys starting at 0
    • Improve error wording of the NonexistentOffset, BooleanAndConstantConditionRule, and BooleanOrConstantConditionRule (#1882), thanks @VincentLanglet!
    • MissingMagicSerializationMethodsRule (#1711), #7482, thanks @staabm!
    • Unescape strings in phpdoc-parser (https://github.com/phpstan/phpstan-src/commit/97786ed8376b478ec541ea9df1c450c1fbfe7461)
    • Stub files validation - detect duplicate classes and functions (https://github.com/phpstan/phpstan-src/commit/ddf8d5c3859c2c75c20f525a0e2ca8b99032373a, https://github.com/phpstan/phpstan-src/commit/17e4b74335e5235d7cd6708eb687a774a0eeead4)

    If you want to see the shape of things to come and adopt bleeding edge features early, you can include this config file in your project's phpstan.neon:

    includes:
    	- vendor/phpstan/phpstan/conf/bleedingEdge.neon
    

    Of course, there are no backwards compatibility guarantees when you include this file. The behaviour and reported errors can change in minor versions with this file included. Learn more

    Improvements πŸ”§

    • Add non-negative-int and non-positive-int (#1803), thanks @rvanvelzen!
    • Optimize NonexistentOffsetInArrayDimFetchCheck (#1801), thanks @herndlm!
    • Modify the built-in @method extension to look at @throws in __call (#1842), #8163, thanks @VincentLanglet!
    • Improve impossible type checker for void-returning functions (#1857), #8169, thanks @rvanvelzen!
    • Allow using $this/static in conditional return types (#1863), thanks @rvanvelzen!
    • Emit warnings when Xdebug is not used according to CLI flags (#1878), thanks @staabm!
    • Improve array_fill return type extension (#1879), thanks @rvanvelzen!
    • Add support for mb_convert_case() and mb_convert_kana() (#1866), thanks @zonuexe!
    • Accept and describe callable-object and callable-string (#1906), thanks @rvanvelzen!
    • Add colon as prefix of line number in table report, when running in VSCode terminal (#1901), #8086, thanks @LeoVie!
    • Cover ExtendedMethodReflection by BC promise (but not implementing it, only calling the methods) (#1913), thanks @staabm!
    • Locate identifiers by type for OptimizedSingleFileSourceLocator (#1114), thanks @tomasfejfar!
    • Implement FunctionReflection/ExtendedMethodReflection::returnsByReference() (#1899), #6005, thanks @staabm!
    • Add noreturn as PseudoTypeClass (#1937), #8242, thanks @zonuexe!
    • Introduce new simple ScopeFactory (https://github.com/phpstan/phpstan-src/commit/1cc337acc877bc02f1a6686fbfe38994a987fbc5)
    • MutatingScope::enterNamespace() is part of BC promise (https://github.com/phpstan/phpstan-src/commit/92732ca8de9d479762337bbc25c629f20d096e0c)

    Bugfixes πŸ›

    • Preserve non-empty-array type when generalizing arrays (#1752), #7996, thanks @herndlm!
    • There's no valid use-case to implement Scope or FunctionReflection in userland class (https://github.com/phpstan/phpstan-src/commit/2796f8dd8fd5156abd8f19f4ecab2be14248782c)
    • no-named-arguments implies variadic argument is a list (#1796), thanks @herndlm!
    • Fix list checking on level 7 vs. level 8 (https://github.com/phpstan/phpstan-src/commit/926058491578747d2f99ec6b02ad28c988f3c28d), #8071
    • MixedType: support subtracted in array-type methods (#1852), #3370, thanks @staabm!
    • Allow compare SimpleXMLElement to number (#1755), #1795, thanks @muno92!
    • Fix min max call on array of union types (#1795), #8088, thanks @VincentLanglet!
    • Support Countable in count() (#1876), thanks @staabm!
    • Improve RuleLevelHelper::accepts() for constant arrays (#1911), #8209, thanks @rvanvelzen!
    • Fix closure return type based on by-ref use (#1914), #6806, #4739, #5753, #6559, #6902, #7220, thanks @rvanvelzen!
    • Consider get_object_var() as private property read (#1902), #3654, thanks @vovochka404!
    • Temporary solution to handle "maybe" certainty types assign in nativeExpressionTypes (#1932), thanks @rajyan!
    • Refactor arrow function scope logic to make it consistent with anonymous functions (#1935), thanks @rajyan!
    • Fix static bleedingEdge toggles in tests (#1928), thanks @rvanvelzen!
    • Improve unset on ConstantArrayType (#1927), #8225, thanks @VincentLanglet!
    • Fix stale result cache for @param-out (https://github.com/phpstan/phpstan-src/commit/cf40007c004d7d24e286b8663a3d0e0ed8f3fbb7)
    • Fix stale result cache for arrow functions (https://github.com/phpstan/phpstan-src/commit/29690576ea459e24b3eab1d2987628c7d166ce09)
    • Fix closure return type for different same-code array_map arguments in same scope (#1915), #8179, thanks @rvanvelzen!
    • $this in nativeExpressionTypes (#1936), thanks @rajyan!
    • Handle ClassConstFetch in Scope (#1944), #7913, thanks @rajyan!
    • Retain non-variable expression types in closure (#1929), #8205, thanks @rvanvelzen!
    • Fix stale result cache for asserts (https://github.com/phpstan/phpstan-src/commit/471265fc62f30504f4a0aecf79585bef42e69213)
    • Fix stale result cache for @phpstan-self-out (#1949), thanks @staabm!

    Function signature fixes πŸ€–

    • Fix class_implements return type (#1797), thanks @enumag!
    • mb_check_encoding() accepts array<string> in PHP 7.2+ (#1867), thanks @zonuexe!

    Internals πŸ”

    • Introduce ArrayType traits (#1715), thanks @herndlm!
    • Introduce Type::getConstantArrays as successor for TypeUtils::getOldConstantArrays (#1684), thanks @herndlm!
    • Deprecate TypeUtils::getArrays() and TypeUtils::getAnyArrays() (#1687), thanks @herndlm!
    • Add Type::getLastIterableValueType() (#1811), thanks @herndlm!
    • Add Type::getFirstIterableValueType() (#1811), thanks @herndlm!
    • Add Type::getFirstIterableKeyType() and Type::getLastIterableKeyType() (#1812), #8152, thanks @herndlm!
    • Preparation for native types (#1823), #5333, thanks @rajyan!
    • Move iterable methods from array to iterable traits (#1821), thanks @herndlm!
    • Do not use other traits in JustNullableTypeTrait (#1821), thanks @herndlm!
    • Add Type::isConstantArray() (#1822), thanks @herndlm!
    • Replace single getConstantArrays() usage with isConstantArray() (#1827), thanks @herndlm!
    • Add Type::getArraySize() (#1828), thanks @herndlm!
    • Add Type::flipArray() (#1832), thanks @herndlm!
    • Add Type::getKeysArray() and Type::getValuesArray() (#1851), thanks @herndlm!
    • Implement FunctionReflection::getDocComment() (#1834), thanks @staabm!
    • Add Type::popArray() and Type::shiftArray() (#1847), thanks @herndlm!
    • Add Type::shuffleArray() (#1853), thanks @herndlm!
    • Deprecate ConstantArrayType::generalizeToArray() (#1856), thanks @herndlm!
    • Explicitly specify native type for array_pop/array_shift arg (#1864), thanks @herndlm!
    • Replace ArrayType::castToArrayKey() with Type::toArrayKey() (#1841), thanks @rvanvelzen!
    • remove IsFloatFunctionTypeSpecifyingExtension (#1880), thanks @staabm!
    • remove IsNumericFunctionTypeSpecifyingExtension (#1880), thanks @staabm!
    • Remove is_bool, is_countable and is_null type specifying extensions (#1881), thanks @mad-briller!
    • Add Type::fillKeysArray() (#1869), thanks @herndlm!
    • Consistently return ErrorType for invalid keys (#1869), thanks @herndlm!
    • Replace is_(int,object,resource,scalar) extensions with stubs (#1884), thanks @BackEndTea!
    • Refactor pow() return type extension to re-use BinaryOp\Pow type inference (#1900), thanks @staabm!
    • Get rid of of Type::getArrays() usage in InvalidKeyInArrayDimFetchRule (#1872), thanks @herndlm!
    • Add Type::searchArray() (#1874), thanks @herndlm!
    • MutatingScope: change variableTypes to save by exprString (#1909), thanks @rajyan!
    • MutatingScope: merge variableTypes and moreSpecificTypes (#1919), thanks @rajyan!
    • Upgrade deprecated ::set-* in GitHub Actions (#1917), thanks @rez1dent3!
    • Improve non-array specification for recently cleaned-up array functions (#1907), thanks @herndlm!
    • Retain sort order in intersection type (#1906), thanks @rvanvelzen!
    • Add Type::intersectKeyArray() (#1916), thanks @herndlm!
    • Changelog generator - allow excluding branch (https://github.com/phpstan/phpstan-src/commit/aaf4b7df4493d44e7ca21e2b52daa2ec2c7c5033)
    • MutatingScope refactoring and regression test (#1934), thanks @rajyan!
    • Refactor to save nativeTypeExpressions by ExpressionTypeHolder (#1936), thanks @rajyan!
    • Merge constantTypes with expressionTypes (#1938), thanks @rajyan!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.15 MB)
    phpstan.phar.asc(833 bytes)
  • 0.12.100(Nov 1, 2022)

    Message from the future

    ⚠️ You're running a really old version of PHPStan.️

    The last release in the 0.12.x series with new features and bugfixes was released on September 12th 2021, that's 415 days ago.

    Since then more than 67 new PHPStan versions were released with hundreds of new features, bugfixes, and other quality of life improvements.

    To learn about what you're missing out on, check out this blog with articles about the latest major releases: https://phpstan.org/blog

    Upgrade today to PHPStan 1.8 or newer by using "phpstan/phpstan": "^1.8" in your composer.json.

    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(18.22 MB)
    phpstan.phar.asc(833 bytes)
  • 1.8.11(Oct 24, 2022)

    Improvements πŸ”§

    • MatchExpressionArmBody virtual node (#1726), thanks @janedbal!
    • Detect duplicate included files in ContainerFactory (https://github.com/phpstan/phpstan-src/commit/f15cd6deea2dda4b41272aa50fb3b61304ad3515, https://github.com/phpstan/phpstan-src/commit/4cdb8060b73fc09e25cf230041532f068974234d)
    • ClassPropertyNode - carry PHPDoc type (https://github.com/phpstan/phpstan-src/commit/dcd8bac24fdbe0723b9307f3f3b2e8e38cc7eae1)

    Bugfixes πŸ›

    • Fix several stale result cache issues:
      • Fix stale @mixin result cache issue (https://github.com/phpstan/phpstan-src/commit/7228d4d5c6ba0289bd67a0b0bd113a6aafed5faa), #7831
      • Include @template tags in the result cache (https://github.com/phpstan/phpstan-src/commit/4c0cb98c84f7c4dfe62e21f6b163529a150861fe)
      • Reanalyse all files with errors when new symbol appears (https://github.com/phpstan/phpstan-src/commit/bc9301d983c03cc5716ee2e00c32713c80e4b53e)
      • DependencyResolver - add method/property declaring classes to dependencies (https://github.com/phpstan/phpstan-src/commit/e1c13669492079f065fd8138680fc91c96c3729a)
      • DependencyResolver - declaring classes for static fetches (https://github.com/phpstan/phpstan-src/commit/be6e7ced22b578d67e58f63b9649ad2ef2c35911)
      • DependencyResolver - @method, @property, @extends, @implements tags (https://github.com/phpstan/phpstan-src/commit/ec5b6331e910e18bec1abfa4a1db8961509c7591)
      • Fix result cache getting stale because of trait @use (https://github.com/phpstan/phpstan-src/commit/08703d1dacf47cc26a33542d0589bf7912c2aeb4)
      • Fix stale result cache for property types (https://github.com/phpstan/phpstan-src/commit/9e4e93b48cc32298c0a1661f14891307a22def7b)
    • Fix wrong type inference about array (#1808), #8087, thanks @VincentLanglet!
    • Invalidate DI container based on included files hashes (https://github.com/phpstan/phpstan-src/commit/615c6a1d6216a0d4b357c67657ba340c88a98a3b)
    • Virtual expr nodes - do not reuse wrong attributes, a printed expr might be cached there (https://github.com/phpstan/phpstan-src/commit/83691977757661e4160c89a533cdaf589434d782)
    • Fix reordering unspecified named arguments (#1903), #8204, thanks @rvanvelzen!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.01 MB)
    phpstan.phar.asc(833 bytes)
  • 1.8.10(Oct 17, 2022)

    Improvements πŸ”§

    • RuleTestCase: enable gathering analyser errors without causing test failures (#1728), thanks @schlndh!

    Bugfixes πŸ›

    • Update BetterReflection to 6.3.0, fixes internal error (https://github.com/phpstan/phpstan-src/commit/9febf1db4b4e3a4f3462fdd6ffa67b22a420f05a), #8139
    • Call nodeCallback with original argument with a name after reordering (https://github.com/phpstan/phpstan-src/commit/ecc3076769a7943e33801d024eeab0b08187c204)

    Function signature fixes πŸ€–

    • Fix a couple CURLOPT_* parameter types (#1836), #8152, #8157, thanks @jlherren!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(19.98 MB)
    phpstan.phar.asc(833 bytes)
  • 1.8.9(Oct 13, 2022)

    Improvements πŸ”§

    • Slightly optimize TypeCombinator::reduceArrays() even more (#1814), thanks @rvanvelzen!
    • Micro optimizations in TypeCombinator (#1816), thanks @mad-briller!
    • Improve array_search() type specifier performance (#1818), #8147, thanks @rvanvelzen!
    • Rule registry now gets rules instances in lazy manner (https://github.com/phpstan/phpstan-src/commit/b1b0dc921894da1f24721702262e64399a39c626)
    • Show progress bar sooner (https://github.com/phpstan/phpstan-src/commit/8e55decc78ab9da6ffe4cc62045c752794ed2d7a)

    Bugfixes πŸ›

    • Make key_exists be treated like array_key_exists (#1800), #8091, thanks @takaram!
    • Fix resolving class types in inherited docblock (#1815), #7839, thanks @rvanvelzen!
    • Fix passing named arguments to by-ref parameter (#1807), #8142, thanks @rvanvelzen!
    • IncompatiblePropertyPhpDocTypeRule - fix inconsistency for stubbed PHPDocs (https://github.com/phpstan/phpstan-src/commit/32b3c67729267a1f7a4dcae590e7ce9013eabfee)
    • non-empty-string can still contain falsy strings as individual characters (https://github.com/phpstan/phpstan-src/commit/76bd347d2281f311ed5aa4a5c8a6632f2f136eff), #8158

    Function signature fixes πŸ€–

    • Fix SoapFault constructor datatype (#1798), thanks @ahmedash95!
    • fix IntlDateFormatter::create return signature (#1776), thanks @Kleinast!
    • Allow string args in signature of RedisCluster::del (#1829), thanks @ostrolucky!
    • Refined fpm_get_status function signature (#1771), thanks @mad-briller!
    • Refined connection_status function signature (#1774), thanks @mad-briller!
    • headers_list() returns a list of headers as strings. (#1770), thanks @johnbillion!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(19.98 MB)
    phpstan.phar.asc(833 bytes)
  • 1.8.8(Oct 6, 2022)

    Improvements πŸ”§

    • Cover ExprPrinter by BC promise (#1794), thanks @staabm!
    • Improve isset specification in falsy scope (#1781), thanks @herndlm!s
    • Update phpstan/phpdoc-parser to 1.9.0 (https://github.com/phpstan/phpstan-src/commit/fd94186ee2a8065c94edb4603dd954584e9e8f45)

    Bugfixes πŸ›

    • Do not drop original specified expression in TypeSpecifier (#1793), #8076, thanks @herndlm!
    • Preserve accessory types in MutatingScope::generalizeType (#1732), #8015, thanks @herndlm!
    • Specify types on get_parent_class() (#1383), #5552, thanks @staabm!
    • Do not load Composer\InstalledVersions to parse PHPStan version (https://github.com/phpstan/phpstan-src/commit/acbb55baeeb2f02b0ea2e61b4321e4f5dd5f65b2), #8117

    Function signature fixes πŸ€–

    • Fix zadd argument order (#1779), thanks @araab!
    • Fix zscan return types (#1780), thanks @araab!
    • XMLWriter::startElementNS() $namespace arg is nullable (#1772), thanks @staabm!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(19.98 MB)
    phpstan.phar.asc(833 bytes)
  • 1.8.7(Oct 4, 2022)

    Improvements πŸ”§

    • Update Roave/BetterReflection to v6 (https://github.com/Roave/BetterReflection/releases/tag/6.0.0)
    • PHP 8.2: Support for readonly classes, RFC (https://github.com/phpstan/phpstan-src/commit/c52eb5792c6e9b7c2d060cafa256b19997552a15)
    • PHP 8.2: Support for DNF types, (RFC)
    • Improve TypeCombinator::reduceArrays() performance with retained type completeness (#1741), thanks @rvanvelzen!
    • Improve unsetting constant offsets on array (#1760), thanks @rvanvelzen!
    • @readonly property allows private mutation (#1610), #7778, thanks @zonuexe!
    • Readonly properties cannot be static (https://github.com/phpstan/phpstan-src/commit/3e383fc9620a46173651402049a8e8c4904591b6)
    • Do not call CollectedDataNode rules if internal errors are present (https://github.com/phpstan/phpstan-src/commit/877835002a2daa758a82a8e0d5502881e7e25aa3)
    • Universal object crate classes now respect @property annotations (#1786), thanks @mad-briller!
    • Add tip message to JSON error formatter (#1727), thanks @staabm!

    Bugfixes πŸ›

    • Fix supertype checks between int range and constant int union (#1742), #3383, #6356, #7594, thanks @rvanvelzen!
    • Fix resolving docblocks in global namespace (using namespace {}) (#1758), thanks @rvanvelzen!
    • Fix ignoreErrors (#1769), thanks @MartinMystikJonas!
    • ignoreErrors: fix reportUnmatched without path/paths (#1773), thanks @MartinMystikJonas!
    • Fix potential assert failures - use getRawArgs() instead (https://github.com/phpstan/phpstan-src/commit/6cd3d5d61db965f2d4d59e2e860201b9afb1d8fc), #8078
    • Fix ArrowFunctionArgVisitor (https://github.com/phpstan/phpstan-src/commit/3758d9d5d5a8c792149238de289ab0e05f11de0e), #8072
    • Fix ClosureArgVisitor (https://github.com/phpstan/phpstan-src/commit/e753dfd4a4d7f67192cd83e7117f39ebdd6e3ceb)
    • Fix circular parent class reference thanks to BetterReflection v6 (https://github.com/phpstan/phpstan-src/commit/8f6392f4521d1d4109e2a79598e820b7ce367a67), #7787
    • Fix infinite loop of global constants referencing each other (https://github.com/phpstan/phpstan-src/commit/33771e5d8ee8b6dbae4f42ce3f8b424a81f68dc9), #8054
    • Fix CURLOPT_POSTFIELDS param type (#1782), thanks @ahmedash95!
    • Remove IssetCheck/MutatingScope::issetCheck deviations and remove too early exits (#1784), thanks @herndlm!
    • Fix issue around generics and MethodsClassReflectionExtension/PropertiesClassReflectionExtension (https://github.com/phpstan/phpstan-src/commit/c052aace4efa157d9594f13fb748965cbfc43be2), #8008
    • Make array access on possible false tolerant with isset (#1791), #8068, thanks @ahmedash95!

    Function signature fixes πŸ€–

    • Fix time_nanosleep return type signature (#1787), #8097, thanks @staabm!

    Internals πŸ”

    • Compile PHAR on PHP 8.1 (#1481)
    • phpstan-src: Require PHP 8.1, use readonly properties (#1767)
    • phpstan-src: Use intersection type (https://github.com/phpstan/phpstan-src/commit/376449e2d4744ec8ee3810321b33a963e89e8280)
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(19.97 MB)
    phpstan.phar.asc(833 bytes)
  • 1.8.6(Sep 23, 2022)

    Improvements πŸ”§

    • ignoreErrors: multiple messages and explicit reportUnmatched (#1686), thanks @MartinMystikJonas!
      • Read more: https://phpstan.org/user-guide/ignoring-errors#reporting-unused-ignores
    • Improve JUnit error formatter (#1722), #6772, thanks @mcaskill!
    • Implement template type inference from conditional return type (#1465), #7141, #7562, thanks @rvanvelzen!
    • Optimize ConstantArrayType::isKeysSupersetOf() (#1729), #8017, thanks @rvanvelzen!
    • Enums cannot implement Serializable (#1713), thanks @staabm!
    • ConditionalTagsExtension: Multiple conditions support (#1697), thanks @MartinMystikJonas!
    • More precise $argc, $argv global variables types (#1718), thanks @staabm!
    • Improve folding of constant arrays (#1739), thanks @rvanvelzen!
    • Introduce oversized-array type to enfore max number of HasOffsetValueType accessory types (#1666), thanks @rvanvelzen!
    • ClassReflection - do not execute properties extensions on PHP 8.2 if the class does not allow dynamic properties (https://github.com/phpstan/phpstan-src/commit/a628fb34293c84c807a1a561883811067e49ebcb)
    • Improve UnionTypeHelper::sortTypes() stability (#1746), thanks @rvanvelzen!

    Bleeding edge πŸ”ͺ

    • Change curl_setopt function signature based on 2nd arg (#1719), thanks @staabm!

    If you want to see the shape of things to come and adopt bleeding edge features early, you can include this config file in your project's phpstan.neon:

    includes:
    	- vendor/phpstan/phpstan/conf/bleedingEdge.neon
    

    Of course, there are no backwards compatibility guarantees when you include this file. The behaviour and reported errors can change in minor versions with this file included. Learn more

    Bugfixes πŸ›

    • Fix checking empty constant arrays in array_pop and array_shift extensions (#1712), #7968, thanks @herndlm!
    • Fix array_filter result for non-trivial callbacks (#1725), #7993, thanks @rvanvelzen!
    • Improve type inference for coalesce (#1716), #7973, thanks @rvanvelzen!
    • Fix assigning generic object without a constructor (like SplObjectStorage) to a nullable property (#1730), #4526, #4680, thanks @rvanvelzen!
    • Accept ::class as literal string (#1692), #7823, thanks @staabm!
    • Fix array_unshift for union of constant arrays (#1738), thanks @rvanvelzen!
    • Improve intersection of generic class string (#1724), #7987, #7200, thanks @rvanvelzen!
    • Downgrade arrays less (https://github.com/phpstan/phpstan-src/commit/5f1a4a5b9c65b588fc4de91804e1ad941a680bd5), #7963
    • Do not call BuilderHelpers::normalizeValue(), it's not needed (https://github.com/phpstan/phpstan-src/commit/ec286787e76b8cebe322d56dde5bdda65f3ebb74), #8029
    • Support autoloaders that rely on the include path and don't check file existence before trying to include a file (#1503), #7526, thanks @pprkut!

    Function signature fixes πŸ€–

    • gnupg::geterror can return false (#1735), thanks @Firehed!
    • Improve pathinfo() return type (#1734), #8033, thanks @rvanvelzen!
    • These stream_* functions all return a list of strings. (#1745), thanks @johnbillion!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.36 MB)
    phpstan.phar.asc(833 bytes)
  • 1.8.5(Sep 7, 2022)

    Improvements πŸ”§

    • PHP 8.2: Support true pseudotypes in native unions (#1539), thanks @staabm!
    • Add dump-parameters command (#1702), #7942, thanks @rvanvelzen!
    • Update phpstan/phpdoc-parser to 1.8.0 (https://github.com/phpstan/phpstan-src/commit/16a80d95554cac8c79fe7d6449e7567f32de9c8a)
    • DefaultExceptionTypeResolver is covered by BC promise (https://github.com/phpstan/phpstan-src/commit/8a3562e81348ecc92cf9883f8077ef7363796ce8)
    • Optimization for various array slowdowns (https://github.com/phpstan/phpstan-src/commit/38953dd44d979be2ed4e26c1e87228d060b6f03f, https://github.com/phpstan/phpstan-src/commit/7e2941ec6ca76ef5f22253ee83ea404173556d33, https://github.com/phpstan/phpstan-src/commit/52b7bec2792fb40fe30e74674239701b2d6f39e7)
    • Reverted some ineffective optimizations (https://github.com/phpstan/phpstan-src/commit/8250448ceac7586cf556b6e9c7858b50f6aa50e7, https://github.com/phpstan/phpstan-src/commit/05dbd5e48c65306c5007af5de2d26f469dba1c3b, https://github.com/phpstan/phpstan-src/commit/ab7760e044bf6fd5b5252b9ce29c4e1d87216f01), #7933

    Bugfixes πŸ›

    • Fix ConstantArrayType::isKeysSupersetOf for tagged unions (#1693), #7898, thanks @herndlm!
    • Fix checking empty constant arrays in array function return type extensions (#1696), #7928, thanks @rvanvelzen!
    • Improve ::class type for final classes (#1699), thanks @rvanvelzen!
    • Fix supertype checks between static and final class (#1703), #7717, #6104, thanks @rvanvelzen!
    • Simplify TemplateTypeTrait (#1705), #7103, thanks @rvanvelzen!
    • Fix numeric string ctype_digit always true type specifier result (#1706), #7914, thanks @rvanvelzen!
    • HasOffsetValueType - fix traverse (https://github.com/phpstan/phpstan-src/commit/5b448a7dce06ca3ade42d32e4c8c50a05c7fcc36)
    • Fix specifying types for left side of null coalesce (#1707), #5304, #7244, #7501, #7639, #7949, thanks @rvanvelzen!
    • Fix scope namespace when entering trait (https://github.com/phpstan/phpstan-src/commit/74309300ba5972461a7cd9ffb33edd6ca005d81e), #7952
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.32 MB)
    phpstan.phar.asc(833 bytes)
  • 1.8.4(Sep 3, 2022)

    PHPStan 1.8.3 but faster!

    Improvements πŸ”§

    • Optimization: Degrade constant arrays if there's too many values recursively (https://github.com/phpstan/phpstan-src/commit/0cc87f37855611868d784deb3d5ec26c5058fda4, https://github.com/phpstan/phpstan-src/commit/ec9240294a85e84fc212f551c92698e6005cf3c1, https://github.com/phpstan/phpstan-src/commit/13d659522cf2b24c12e14183e8932e8f7270bcd3), #7918, #7903, #7901, #7581
    • Improve dead code detection after nested function calls with conditional never return type (#1378), #7188, thanks @rvanvelzen!
    • EnumCaseObjectType constructor made part of BC promise (https://github.com/phpstan/phpstan-src/commit/1a8f07040d37a68e612a771e67322e8f624ae6aa), #7917

    Bugfixes πŸ›

    • Fix ::class on string expression (#1425), thanks @rvanvelzen!
    • Anonymous classes are final (https://github.com/phpstan/phpstan-src/commit/a418c461fab8f118f99b2f6e1e72fd07a4800e1d), #7904
    • Result cache needs to be cleared after reportUnmatchedIgnoredErrors is changed (https://github.com/phpstan/phpstan-src/commit/84852ab8d9d4cbe3939d6f55e48e20f0481c3166)
    • Fix array_filter() that does not return all items (https://github.com/phpstan/phpstan-src/commit/2e89a22dc28a044b65dc8f2bf7c76fd0b65f66ee), #7909
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.32 MB)
    phpstan.phar.asc(833 bytes)
  • 1.8.3(Sep 1, 2022)

    This release fixes 76 issues!Β :tada:

    Improvements πŸ”§

    • Added non-falsy-string (truthy-string) type (#1542, #1660, #1661, #1662), #5317, #5370, #7199, thanks @staabm!
    • New configuration option: checkImplicitMixed (#1645), thanks @MartinMystikJonas!
    • Support constant string-unions in substr() (#1532), #7663, thanks @staabm!
    • Tagged unions preparation (#1548), #5232, #7511, #7224, #6997, #6556, #6181, #5743, #4708, #3821, #2911, #7156, #6728, #6364, #5758
    • Tagged unions (#1547), #6469, #3801, #6599
    • Added error message to impossible instanceof rule to warn when comparing a trait (#1570), thanks @mad-briller!
    • Implement ltrim() return type extension to support class-string (#1597), #7483, thanks @staabm!
    • Improve type inference from conditional return type (#1604), thanks @rvanvelzen!
    • Optimization: ArrayType::setOffsetValueType() - generalize key + item type if it goes over a threshold (https://github.com/phpstan/phpstan-src/commit/24aee609ebf91b0100e2f60b78cde5a785936b81, https://github.com/phpstan/phpstan-src/commit/10ba3c681647b281f774f48fb1843d4b5c75b7da)
    • Optimization: ConstantArrayTypeBuilder - generalize key types and value types in degraded general array (https://github.com/phpstan/phpstan-src/commit/dbdcb817fced0f375a420fc3bff44c2d331c856d)
    • Make @psalm-readonly-allow-private-mutation as alias of @readonly (#1609), #7774, thanks @zonuexe!
    • Implement gettype() inference in TypeSpecifier (#1611), #6901, thanks @staabm!
    • Use argument types as parameter types for inline closures (#7798) (#1628), #7798, thanks @leongersen!
    • Optimization: inline calls in TrinaryLogic to reduce method call overhead (#1563), thanks @staabm!
    • Handle the expression expr & number for positive numbers (#1629), thanks @thg2k!
    • Add type specifying extension for ctype_digit (#1635), thanks @fluffycondor!
    • array_flip() for constant arrays (https://github.com/phpstan/phpstan-src/commit/a6cec395f64806bd12522926970843423f3f7290)
    • array_filter() for constant arrays (https://github.com/phpstan/phpstan-src/commit/771b860d0c7ca73bfb255df4c14cffa97caada93)
    • array_intersect_key() for constant arrays (https://github.com/phpstan/phpstan-src/commit/a96cdf2bf5cf2b145a5c0fbbe007776e8d7bd7b8)
    • Enfore optional parameters in callable types (#1354), #7320, thanks @rvanvelzen!
    • Optimization: match/enum performance (https://github.com/phpstan/phpstan-src/commit/092ef3be68a8e478dec09bbeb779fff46b09c023)
    • Optimization: TrinaryLogic - lazy evaluation methods (https://github.com/phpstan/phpstan-src/commit/f8f6e2a8df9499e5f9603935a2557964c285fae4)

    Bugfixes πŸ›

    • Support ConstantArrayType callables with union values (#1529), #2343, thanks @herndlm!
    • PHPDoc readonly rules do not report for native readonly props (#1521), #7648, thanks @herndlm!
    • Fix error for custom autoloaders calling eval() (https://github.com/phpstan/phpstan-src/commit/058d739904a9f0641e5643fd8b089d2203f9c1d3), #7647
    • Remove undefined constants from scope (#1534), thanks @herndlm!
    • Fixed double reporting of promoted properties (#1533), #7662, thanks @mad-briller!
    • Fixed extracting PHP 8 stubs (https://github.com/phpstan/php-8-stubs/commit/363a282adde9457b2158580df4da8d83c7d95527), #7676
    • Remove old pg_* functions with multiple variants from signature map on PHP 8.1 (https://github.com/phpstan/phpstan-src/commit/8128a63348918ee3d94eb8ba513252c1188b5cc3), #7138
    • Fix ObjectType resolving inside bound Closure (#1543), #7675, thanks @herndlm!
    • Fix in_array non-empty-array type specification (#1545), #7684, thanks @herndlm!
    • Fix incorrect mixed template type for impossible union template type intersection (#1546), #7688, thanks @rvanvelzen!
    • Improve ConstantArrayType::unsetOffset (#1537), #5223, thanks @herndlm!
    • Fix incorrect incomplete match error for treatPhpDocTypesAsCertain: false (#1560), #7622, thanks @rvanvelzen!
    • Fix variable certainty after exhaustive switch (#1561), #1016, thanks @rvanvelzen!
    • Fix resolving variants for union type methods (#1574), #7593, #6946, #5754, thanks @rvanvelzen!
    • Fix assigning arbitrary expressions in foreach key (#1582), #7737, thanks @rvanvelzen!
    • Assume offset value set was successful for further analysis (https://github.com/phpstan/phpstan-src/commit/1537424191a4cf27577dd3cfc07d162b09c20a12), #7469, #3391, #7417
    • Support removing class-strings from GenericClassStringType (#1590), #7698, thanks @staabm!
    • Fix Array_ expr type resolving with unpacked array items (#1586), #7724, thanks @herndlm!
    • Fix Array_ expr type resolving with unpacked constant array items (#1619), #7776, thanks @herndlm!
    • ArrayDimFetch: assign vs. narrowing a type (https://github.com/phpstan/phpstan-src/commit/229df9ba73177149f3db8d476ca2c41b065c8092)
    • Discover BetterReflection sources using PSR-4 (https://github.com/phpstan/phpstan-src/commit/8ab002a13a6a94cfab24284b48e7ad4c5bd60973)
    • Fix internal error with json_decode() without arguments (https://github.com/phpstan/phpstan-src/commit/bf6d4c003a589f2dd75dacab8306c336bb9ff81c), #7762
    • array_key_exists - fix for AST-based offset (https://github.com/phpstan/phpstan-src/commit/8613169c105fd38d4cdbdc56e3655be822ef4ed2), #7763
    • Escape control characters in ConstantStringType::describe() (#1612), thanks @rvanvelzen!
    • Fix offset access + key-of template type combination (#1623), #7788, thanks @rvanvelzen!
    • Fix array_search extension incorrectly returning null (#1633), #7809, thanks @herndlm!
    • Specify existent offset with key variable when entering foreach (https://github.com/phpstan/phpstan-src/commit/14592ddf2b9dd454430c61c525b35894ae446856)
    • Generalize file and dir magic constants (https://github.com/phpstan/phpstan-src/commit/f09b288ac022c9ba5cb490f6877c37fac2b2c7c9)
    • Unsetting an offset should remove non-empty-array (https://github.com/phpstan/phpstan-src/commit/32353a92691b88c4f662d170a165efa7910e330c)
    • Narrow $data[$key] after specifying $key (https://github.com/phpstan/phpstan-src/commit/46a8f32f5474b6f6127fb17a1638e7e11897be52), #6008
    • Fix PreInc/PreDec of NeverType (#1641), #7044, #3277, thanks @herndlm!
    • Consider MixedType explicitness in MethodParameterComparisonHelper::isTypeCompatible (#1491), #7415, thanks @herndlm!
    • Do not consider mixed explicitness for parameter contravariance (#1648), thanks @herndlm!
    • serialize/unserialize is not allowed in enum (#1643), #7837, thanks @staabm!
    • Fixed generalizing arrays in scope, simplified offset unset in ConstantArrayType (https://github.com/phpstan/phpstan-src/commit/617311022636af148ce910635adf85624fe59f8f), #6013, #2851, #6008
    • Fix NeverType for more operators (#1649), thanks @staabm!
    • support length parameter in sscanf() (#1593), thanks @staabm!
    • sscanf: allow nulls in returned array (#1577), #7735, thanks @staabm!
    • Fixed comparison of empty array with a scalar type (#1650), thanks @staabm!
    • Fix sscanf() inference with regex format patterns (#1576), #7563, #7764, thanks @staabm!
    • Resources may be opened or closed (#1617), #5845, thanks @staabm!
    • Fix ConstantArrayType intersecting with HasOffsetValueType (https://github.com/phpstan/phpstan-src/commit/9c49d4c913f3df7579269f457bfdea282c9c2036)
    • Take subtracted type into account in MixedType (#1656), thanks @staabm!
    • Fix resolving mixed + array (#1579), #7492, #6783, #3872, thanks @staabm!
    • Fixed non-falsy-string inference with '0' (#1658), #7877, #7881, thanks @staabm!
    • Fix numeric-string negated intersection (#1639), #7814, thanks @fluffycondor!
    • Make PHPStan\dumpType pure (#1665), #7803, thanks @rvanvelzen!
    • Fix wrong message - Instanceof between Xxx and string (#1669), #5728, thanks @lulco!
    • Fix unset bug (https://github.com/phpstan/phpstan-src/commit/024738fcc7fe98eec72a274ee742a51442a681a3), #6170
    • Make ArrayKeyExistsFunctionTypeSpecifyingExtension understand an empty array (https://github.com/phpstan/phpstan-src/commit/c057aa9d1feff5ce61f96f397ef92e7389a17477)

    Function signature fixes πŸ€–

    • Imagick::queryFontMetrics more specific return type (#1530), thanks @MartkCz!
    • Imagick::roundCornersImage correct naming and optional params (#1531), thanks @MartkCz!
    • str_split returns an empty array since PHP 8.2 (#1544), thanks @herndlm!
    • XmlReader::next|read() has side-effects (#1551), #5920, thanks @staabm!
    • Reflection: getName() returns a non-empty-string (#1599), #7056, thanks @staabm!
    • More precise ord() signature (#1620), thanks @thg2k!
    • More specific type for port component of 'parse_url() (#1622), thanks @thg2k!
    • Allow null as second parameter for json_decode (#1672), thanks @webmaster777!
    • Encoding functions returns non-empty-string (#1664), thanks @staabm!

    Internals πŸ”

    • HasOffsetType - create only for ConstantIntegerType|ConstantStringType (https://github.com/phpstan/phpstan-src/commit/0a2fc63e1fc7414bf96df2e0879f689e3c4bdd00)
    • Simplify non-empty-array removal in array_push/array_unshift (#1552), thanks @herndlm!
    • Fix VirtualNode::getType() returning an incorrect value for ClassConstantsNode and MethodReturnStatementsNode (#1568), thanks @Muqsit!
    • Add return type stub for SimpleXMLElement::asXML (#1606), thanks @herndlm!
    • Simplify TypeSpecifier (#1613), thanks @staabm!
    • Avoid unnecessary intersection in MutatingScope::filterBySpecifiedTypes (#1536), thanks @herndlm!
    • Make IntegerRangeType constructor private (#1624), #7803, thanks @herndlm!
    • Remove jean85/pretty-package-versions dependency (#1607), thanks @herndlm!
    • Require brianium/paratest ^6.5 to fix PHP 8.2 deprecation notices (#1631), thanks @herndlm!
    • Replace pickArrays method in array_search extension with getAnyArrays helper (#1632), thanks @herndlm!
    • Intersect HasOffsetValue type only with possible arrays (#1634), thanks @herndlm!
    • Avoid benevolent union behaviour for more type methods (#1644), thanks @herndlm!
    • Use isArray instead of array supertype checks (#1634), thanks @herndlm!
    • Use isString instead of string supertype checks (#1634), thanks @herndlm!
    • Make MutatingScope::invalidateMethodsOnExpression() private (https://github.com/phpstan/phpstan-src/commit/f3fe24577f0cff89dafaa3a68b9b37dcdf851cb1)
    • Deprecate TypeUtils::containsCallable() (#1667), thanks @herndlm!
    • Use TypeUtils::getOldConstantArrays in array_pop and array_shift extensions (#1668), thanks @herndlm!
    • Use TypeUtils::getOldConstantArrays in array_fill_keys extension (#1676), thanks @herndlm!
    • Use TypeUtils::getOldConstantArrays in array_reduce extension (#1677), thanks @herndlm!
    • Use TypeUtils::getOldConstantArrays in array pointer functions extension (#1678), thanks @herndlm!
    • Use TypeUtils::getOldConstantArrays in array_map extension (#1680), thanks @herndlm!
    • Use TypeUtils::getOldConstantArrays in RegularExpressionPatternRule (#1679), thanks @herndlm!
    • Use TypeUtils::getOldConstantArrays in array_key_first and array_key_last extensions (#1681), thanks @herndlm!
    • Use TypeUtils::getOldConstantArrays in array_intersect_key extension (#1682), thanks @herndlm!
    • Use TypeUtils::getOldConstantArrays in array_column extension (#1683), thanks @herndlm!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.32 MB)
    phpstan.phar.asc(833 bytes)
  • 1.8.2(Jul 20, 2022)

    Improvements πŸ”§

    • Basic support for PHP 8.2
      • #[\AllowDynamicProperties] attribute support (RFC)
      • #[\SensitiveParameter] attribute support (RFC)
      • Updated function signatures
      • Fixed deprecations in PHPStan
    • --debug: print previous exceptions (https://github.com/phpstan/phpstan-src/commit/a342b2bea01895e921c5f669a9a53bd0b1402ed3), #7590
    • Changed the MutatingScope class to not include impossible arms in it's resulting union type. (#1515), thanks @mad-briller!

    Bugfixes πŸ›

    • Properly cache late resolvable types results (#1518), #7637, thanks @rvanvelzen!
    • Fix supertype checks between late resolvable types (#1523), #7652, thanks @rvanvelzen!

    Function signature fixes πŸ€–

    • Update AppendIterator stub (#1517), thanks @drupol!
    • Update CachingIterator::getCache stub (#1519), thanks @drupol!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.23 MB)
    phpstan.phar.asc(833 bytes)
  • 1.8.1(Jul 12, 2022)

    Improvements πŸ”§

    • ReadWritePropertiesExtensions are part of ClassPropertiesNode (https://github.com/phpstan/phpstan-src/commit/49c27d8849b1d153a67f28e612e490a71b4fd477), https://github.com/phpstan/phpstan-src/pull/1480#issuecomment-1169960148
    • Add ClosureTypeFactory (#1484), https://github.com/phpstan/phpstan/discussions/7546, thanks @canvural!
    • Handle native function @throws tag in stub file (#1487), #7552, thanks @VincentLanglet!
    • Add #[AllowDynamicProperties] PHP 8.2 attribute stub (#1478), thanks @andypost!
    • Add rule that disallows final private methods on PHP 8.0+ (#1490), thanks @herndlm!
    • Inherit @immutable phpdoc (#1489), #7506, thanks @herndlm!
    • Mark ClassReflection::evictPrivateSymbols() as internal (https://github.com/phpstan/phpstan-src/commit/9138ab2a1b63d9ee31764cc812cca404f265ecb7)

    Bugfixes πŸ›

    • Fix type specification of various string functions with constant strings in a falsey context (#1488), #7555, thanks @herndlm!
    • Fix ConstantArrayType creation for preg_split with PREG_SPLIT_OFFSET_CAPTURE (#1486), #7554, thanks @herndlm!
    • Reindex constant arrays via shuffle (#1438), #6138, thanks @herndlm!
    • Fix union and intersection between StaticType and ThisType (https://github.com/phpstan/phpstan-src/commit/e20e9345f57a7cd760967f459aa1eedfe2eabff8), #6291, #7211, #7550
    • Enhance FILTER_VALIDATE_INT option in filter_var (#1499), #7608, thanks @takeokunn!
    • Fix handling of str_split / mb_str_split string arg compound types (#1496), #7580, thanks @herndlm!
    • Fix Identical type specification of constant types (#1493), #7257, #6781, #6647, #5896, #5474, #6000, thanks @herndlm!
    • Better StaticType::traverse() (https://github.com/phpstan/phpstan-src/commit/0e257067ff92fbcb37b034cccdbea864a233c198)
    • GenericClassStringType::isSuperTypeOf() - do not convert maybe into no (https://github.com/phpstan/phpstan-src/commit/6fba5429b9784801a89cdc6cfa3d6f8cfd1d82e8), #6697
    • Fix subtractable StaticType (https://github.com/phpstan/phpstan-src/commit/0906336d29e807baba1a9eeca7b1545240c4ce5c), #6443

    Function signature fixes πŸ€–

    • Fix return type of octdec() (#1500), thanks @zonuexe!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.20 MB)
    phpstan.phar.asc(833 bytes)
  • 1.8.0(Jun 29, 2022)

    Major new features πŸš€

    • Collectors - allows writing custom rules that target the whole project
      • Read more: https://phpstan.org/developing-extensions/collectors
    • New rememberPossiblyImpureFunctionValues config parameter (defaults to true) (https://github.com/phpstan/phpstan-src/commit/50ed38f04de93b4d0ea9573d0a4789853a4b9f32), #7529 *Β Read more: https://phpstan.org/config-reference#rememberpossiblyimpurefunctionvalues

    Bleeding edge πŸ”ͺ

    • Check that each trait is used and analysed at least once - level 4 (https://github.com/phpstan/phpstan-src/commit/c4d05276fb8605d6ac20acbe1cc5df31cd6c10b0)
    • Check that PHPStan class in class constant fetch is covered by backward compatibility promise (https://github.com/phpstan/phpstan-src/commit/9e007251ce61788f6a0319a53f1de6cf801ed233)

    If you want to see the shape of things to come and adopt bleeding edge features early, you can include this config file in your project's phpstan.neon:

    includes:
    	- vendor/phpstan/phpstan/conf/bleedingEdge.neon
    

    Of course, there are no backwards compatibility guarantees when you include this file. The behaviour and reported errors can change in minor versions with this file included. Learn more

    Improvements πŸ”§

    • Type a ranged value for filter_var(FILTER_VALIDATE_INT) (#1443), #7494, thanks @zonuexe!
    • Allow BooleanAnd and BooleanOr as standalone expressions with right sides always false (https://github.com/phpstan/phpstan-src/commit/f9374e74beec7082228454693dcdc14000070266), #2741
    • Added @api annotation to NodeScopeResolver::processStmtNodes() (#1464), thanks @vojtech-dobes!
    • Add ClassReflection->is() shortcut (#1468), thanks @janedbal!
    • Force update of the PHPStan Pro PHAR in case of crash (https://github.com/phpstan/phpstan-src/commit/b95606ec291a7cf926ca757e544bfa089da950aa)
    • Intersect optimization for large unions (#1471), thanks @neclimdul!
    • Update phpdoc-parser (https://github.com/phpstan/phpstan-src/commit/7aa19e02c60c75961333d99cfb5c4704796d6e55)
      • Simplify parsing of type alias import (https://github.com/phpstan/phpdoc-parser/pull/137), thanks @jiripudil!
      • Support @template-contravariant tags (https://github.com/phpstan/phpdoc-parser/pull/140), thanks @autaut03!

    Bugfixes πŸ›

    • Prevent crashing for negative bit shifts (#1447), #7490, thanks @rvanvelzen!
    • Fix infinite recursion for template intersection type accepts() (#1450), #7500, thanks @rvanvelzen!
    • Run with parallel runner only when proc_open is not disabled (#1451), #7488, thanks @mvorisek!
    • Suppress is_file warnings in bin/phpstan (#1466), thanks @mvorisek!
    • Fix specifying types for chained assignments (#1473), #7142, thanks @rvanvelzen!
    • Consider autoloaders passed in -a (https://github.com/phpstan/phpstan-src/commit/78016fe92840c02a5981f4ab2ea28fc2d3e49f27)

    Function signature fixes πŸ€–

    • Closure::bind() with $newScope = null (#1446), #7489, thanks @rvanvelzen!
    • Closure::bindTo() with $newScope = null (#1448), thanks @mvorisek!
    • Fix return type for imagesx and imagesy functions (#1452), thanks @norkunas!
    • Add NoRewindIterator stub (#1453), thanks @drupol!
    • Add LimitIterator stub (#1455), thanks @drupol!
    • Add InfiniteIterator stub (#1454), thanks @drupol!
    • Add CachingIterator stub (#1456), thanks @drupol!
    • Add RegexIterator stub (#1462), thanks @drupol!
    • Add EmptyIterator stub (#1472), thanks @drupol!
    • Narrow return type of array_keys slightly (#1474), thanks @Seldaek!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.18 MB)
    phpstan.phar.asc(833 bytes)
  • 1.7.15(Jun 20, 2022)

    Improvements πŸ”§

    • Support for relative paths in editorUrl for Docker environment (#1414), #7043, thanks @Wirone!
    • Support positional arguments in sprintf() constant format inference (#1437, #1440, #1441), thanks @staabm!
    • Dynamic return type extension for sscanf() and fscanf() (#1434), thanks @staabm!
    • Virtual nodes (InClassMethodNode, InFunctionNode, InClosureNode) - pass and provide getters for specific reflection so that Scope::getFunction() does not need to be used (https://github.com/phpstan/phpstan-src/commit/f18bd86495fc6811ee04c305ff4b379b10cd07bb)

    Bleeding edge πŸ”ͺ

    • Check code in custom PHPStan extensions for runtime reflection concepts like is_a() or class_parents() (https://github.com/phpstan/phpstan-src/commit/c4a662ac6c3ec63f063238880b243b5399c34fcc)
    • Check code in custom PHPStan extensions for runtime reflection concepts like new ReflectionMethod() (https://github.com/phpstan/phpstan-src/commit/536306611cbb5877b6565755cd07b87f9ccfdf08)
    • ApiInstanceofRule
      • Report instanceof of classes not covered by backward compatibility promise (https://github.com/phpstan/phpstan-src/commit/ff4d02d62a7a2e2c4d928d48d31d49246dba7139)
      • Report instanceof of classes covered by backward compatibility promise but where the assumption might change (https://github.com/phpstan/phpstan-src/commit/996bc69fa977aa64f601bd82b8a0ae39be0cbeef)

    If you want to see the shape of things to come and adopt bleeding edge features early, you can include this config file in your project's phpstan.neon:

    includes:
    	- vendor/phpstan/phpstan/conf/bleedingEdge.neon
    

    Of course, there are no backwards compatibility guarantees when you include this file. The behaviour and reported errors can change in minor versions with this file included. Learn more

    Bugfixes πŸ›

    • Fix return type for arrow function generators (#1422), #7031, thanks @rvanvelzen!
    • Improve intersecting constant array with general array (#1429), thanks @rvanvelzen!
    • Allow numeric-string being returned for non-empty-string (#1428), #7265, thanks @staabm!
    • Specify array type via in_array (#1430), #7153, #7275, thanks @rvanvelzen!
    • Specify non-empty-array after after in_array() (#1108), #6167, thanks @staabm!
    • Array after array_push / array_unshift call can still be empty (#1431), #7424, thanks @herndlm!
    • Fix TemplateTypeArgumentStrategy::accepts() (https://github.com/phpstan/phpstan-src/commit/85ab8cfe237b9a90d12f211dd1938a99cc299bba), #7460
    • Improve parenthesization for union types (#1433), #7484, thanks @rvanvelzen!
    • Result cache is invalidated for files where PHP 8 attributes changed (#1427), #6797, #7413, thanks @olsavmic!
    • Fix TypeCombinator::union() for intersection of array and template type (#1444), #4117, thanks @rvanvelzen!

    Function signature fixes πŸ€–

    • Be more specific about the XHProf sampling type (xhprof_sample_disable()) (#1436), thanks @johnbillion!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.14 MB)
    phpstan.phar.asc(833 bytes)
  • 1.7.14(Jun 14, 2022)

    Improvements πŸ”§

    • Update phpdoc-parser
      • Micro-optimize lexer (https://github.com/phpstan/phpdoc-parser/pull/135), thanks @rvanvelzen!
    • Update BetterReflection to 5.6.0 (#1421), #7429, #7428
    • Add dynamic return type extension for date_create (#1413), thanks @VincentLanglet!
    • more precise sprintf() return type on constant formats (#1410), #7387, thanks @staabm!
    • Update PhpStorm stubs (#1419)
    • Assert functions do not throw anything (https://github.com/phpstan/phpstan-src/commit/9878eef9a7b04b8a7fa14b004ebfbb1e3d5cb0a8)
    • Deprecate MutatingScope::enterCatch() (https://github.com/phpstan/phpstan-src/commit/4a7d7da6f57be75e3f0dbc4b048663dbd5a58e1d)

    Bugfixes πŸ›

    • Support literal-string as array key (#1420), #7353, #6163, thanks @rvanvelzen!

    Function signature fixes πŸ€–

    • Update string compare return values (#1412), thanks @bytestream!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.11 MB)
    phpstan.phar.asc(833 bytes)
  • 1.7.13(Jun 13, 2022)

    Improvements πŸ”§

    • Optimization of printing expressions using ExprPrinter (https://github.com/phpstan/phpstan-src/commit/e12524e21537b970c91e363c616503e6d7d41f38, https://github.com/phpstan/phpstan-src/commit/fba292944a67cb91158042a0f952e5e15bcf30c7)
    • Do not require an existing filename when reading PHPDocs from an evaled class (#1409), #7441
    • StatementExitPoint and ThrowPoint covered by BC promise (https://github.com/phpstan/phpstan-src/commit/e8b8ffdd7d164a7ddcafcf6cb570f56b71bb2263)
    • Update phpdoc-parser #7426
      • Optimize Lexer::tokenize() (https://github.com/phpstan/phpdoc-parser/pull/133), thanks @rvanvelzen!
      • Optimize generated regex (https://github.com/phpstan/phpdoc-parser/pull/134), thanks @rvanvelzen!

    Bleeding edge πŸ”ͺ

    • Use explicit mixed for global array variables (#1411), thanks @herndlm!

    If you want to see the shape of things to come and adopt bleeding edge features early, you can include this config file in your project's phpstan.neon:

    includes:
    	- vendor/phpstan/phpstan/conf/bleedingEdge.neon
    

    Of course, there are no backwards compatibility guarantees when you include this file. The behaviour and reported errors can change in minor versions with this file included. Learn more

    Bugfixes πŸ›

    • Fix incorrect UnhandledMatchError for match expressions using spaceship operator (#1408), #4451, thanks @rvanvelzen!
    • Fix resolving class const fetch for constant strings (#1416), #7391, thanks @rvanvelzen!
    • Fix resolving user-defined constants in sub-namespaces (#1415), #7352, thanks @rvanvelzen!
    • TypeUtils::getDirectClassNames() - return unique list of class names (https://github.com/phpstan/phpstan-src/commit/b85fce0707f65a633163d2bf5215e57c927011b9)
    • Fix "missing return" for void/never conditional return types (#1418), #7384, thanks @rvanvelzen!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.11 MB)
    phpstan.phar.asc(833 bytes)
  • 1.7.12(Jun 9, 2022)

    Improvements πŸ”§

    • Update phpstan/phpdoc-parser to 1.6.0 (https://github.com/phpstan/phpstan-src/commit/ef8c7c37f2ab3def07860a4cdc20c7ed56758a8c)
      • Allow omitting @param type (https://github.com/phpstan/phpdoc-parser/pull/127), https://github.com/phpstan/phpdoc-parser/issues/77, thanks @rvanvelzen!
      • Support all atomic types as nullable types (https://github.com/phpstan/phpdoc-parser/pull/129), https://github.com/phpstan/phpdoc-parser/issues/124, thanks @rvanvelzen!
    • Support constant string and integer as template bound (#1402), #7381, thanks @rvanvelzen!
    • Introduce ExtendedMethodReflection interface (#1403)
      • The purpose of this interface is to be able to answer more questions about methods without breaking backward compatibility with existing MethodsClassReflectionExtension.
      • Developers are meant to only use the MethodReflection interface and its methods in their code.
      • Methods on ExtendedMethodReflection are subject to change.

    Bleeding edge πŸ”ͺ

    • PHPDoc parser: Require whitespace before description with limited start tokens (https://github.com/phpstan/phpdoc-parser/pull/128), https://github.com/phpstan/phpdoc-parser/issues/125, thanks @rvanvelzen!

    If you want to see the shape of things to come and adopt bleeding edge features early, you can include this config file in your project's phpstan.neon:

    includes:
    	- vendor/phpstan/phpstan/conf/bleedingEdge.neon
    

    Of course, there are no backwards compatibility guarantees when you include this file. The behaviour and reported errors can change in minor versions with this file included. Learn more

    Bugfixes πŸ›

    • Fix node scope resolving of array/list expression assignments (#1405), #7119, thanks @herndlm!
    • Do not consider arrays with an unknown class string to be a callback (#1404), #7389, thanks @herndlm!
    • Add array_udiff to arrayFunctions.stub (#1407), #6105, thanks @akalineskou!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.11 MB)
    phpstan.phar.asc(833 bytes)
  • 1.7.11(Jun 7, 2022)

    Bleeding edge πŸ”ͺ

    • Add @readonly rule that disallows default values (#1391), thanks @herndlm!

    If you want to see the shape of things to come and adopt bleeding edge features early, you can include this config file in your project's phpstan.neon:

    includes:
    	- vendor/phpstan/phpstan/conf/bleedingEdge.neon
    

    Of course, there are no backwards compatibility guarantees when you include this file. The behaviour and reported errors can change in minor versions with this file included. Learn more

    Bugfixes πŸ›

    • BetterReflectionProvider::getClass() - handle InvalidIdentifierName too (https://github.com/phpstan/phpstan-src/commit/64b0907db03da40ecb3d98bde905bbc3214bb08d), #7404
    • BetterReflection: ReflectionClass adapter - implement newInstance* methods (https://github.com/ondrejmirtes/BetterReflection/commit/90dd5834447f8a184ff312855bdae2b793c34748), https://github.com/phpstan/phpstan/discussions/7403
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.10 MB)
    phpstan.phar.asc(833 bytes)
  • 1.7.10(Jun 3, 2022)

    Improvements πŸ”§

    • Adapt to different vendor-dir setting in composer.json, and also COMPOSER environment variable (#1384), thanks @canvural!

    Bugfixes πŸ›

    • Fix BC break in PHPStan\Node\ClassMethod (https://github.com/phpstan/phpstan-src/commit/9b4a5913aa47d94acb47e3c06fce83db8ea5fd8b), https://github.com/phpstan/phpstan-src/commit/d0a9d084ea66be4afdf965dd51e1b6d91d36c6b7#r75178623
    • Fix TypeUtils::getDirectClassNames for nested type (#1380), thanks @mvorisek!
    • Consistent gathering of all stub files for their analysis (#1355), thanks @canvural!
    • Dont report unsafe static if constructor is in both parent and interface (#1395), #6007, thanks @canvural!

    Internals πŸ”

    • Added <file>bin</file>into phpcs.xml, and applied it (#1393, #1394), thanks @sasezaki!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.09 MB)
    phpstan.phar.asc(833 bytes)
  • 1.7.9(Jun 2, 2022)

  • 1.7.8(Jun 1, 2022)

    Improvements πŸ”§

    • Update nikic/php-parser to 4.14.0 (https://github.com/phpstan/phpstan-src/commit/fbaab8f9a65fb0655b0322c792d914feb399e27e)

    Bugfixes πŸ›

    • Improve unresolved template type checks for complex conditional types (#1377), thanks @rvanvelzen!
    • FileCacheStorage - suppress potential file load issue (https://github.com/phpstan/phpstan-src/commit/b73a3962176ddcb6c3ddcd1e6f688900ebe9df1f)
    • Do not overwrite promoted property PHPDoc with constructor PHPDoc (#1376), #7361, thanks @herndlm!
    • Fix/native type specification (#1372), thanks @rajyan!

    Function signature fixes πŸ€–

    • Fix signatures of PDO::pgsqlCopy{From,To}{Array,File} (#1375), thanks @takaram!
    Source code(tar.gz)
    Source code(zip)
    phpstan.phar(20.09 MB)
    phpstan.phar.asc(833 bytes)
  • 1.7.7(May 31, 2022)

Owner
PHPStan
PHP Static Analysis Tool - discover bugs in your code without running it!
PHPStan
A static php code analysis tool using the Graph Theory

Mondrian Ok guyz, you have a master degree in Graph Theory, you follow Law of Demeter and you live on S.O.L.I.D principles ? Let's have some Fun ! (^Ο‰

Florent Genette 391 Nov 30, 2022
Beautiful and understandable static analysis tool for PHP

PhpMetrics PhpMetrics provides metrics about PHP project and classes, with beautiful and readable HTML report. Documentation | Twitter | Contributing

PhpMetrics 2.3k Dec 22, 2022
A static analysis tool for finding errors in PHP applications

Psalm Psalm is a static analysis tool for finding errors in PHP applications. Installation To get started, check out the installation guide. Live Demo

Vimeo 5k Jan 2, 2023
A static analysis tool for security

progpilot A static analyzer for security purposes Only PHP language is currently supported Installation Option 1: use standalone phar Download the lat

null 271 Dec 27, 2022
Performs advanced static analysis on PHP code

PHP Analyzer Please report bugs or feature requests via our website support system ? in bottom right or by emailing [email protected]. Contri

Continuous Inspection 443 Sep 23, 2022
Static code analysis to find violations in a dependency graph

PhpDependencyAnalysis PhpDependencyAnalysis is an extendable static code analysis for object-oriented PHP-Projects to generate dependency graphs from

Marco Muths 546 Dec 7, 2022
The Exakat Engine : smart static analysis for PHP

Exakat The Exakat Engine is an automated code reviewing engine for PHP. Installation Installation with the phar Phar is the recommended installation p

Exakat 370 Dec 28, 2022
Static Analysis Results Baseliner

Static Analysis Results Baseliner (SARB) Why SARB Requirements Installing Using SARB Examples Further reading Why SARB? If you've tried to introduce a

Dave Liddament 151 Jan 3, 2023
Infection Static Analysis Plugin

Static analysis on top of mutation testing - prevents escaped mutants from being invalid according to static analysis

Roave, LLC 108 Jan 2, 2023
A full-scale PHP sandbox class that utilizes PHP-Parser to prevent sandboxed code from running unsafe code

A full-scale PHP 7.4+ sandbox class that utilizes PHP-Parser to prevent sandboxed code from running unsafe code. It also utilizes FunctionParser to di

Corveda 192 Dec 10, 2022
A full-scale PHP 5.3.2+ sandbox class that utilizes PHPParser to prevent sandboxed code from running unsafe code.

##DEPRECATED: The PHPSandbox project has transfered to Corveda/PHPSandbox and will be actively maintained there. This branch is no longer being active

Elijah Horton 219 Sep 2, 2022
A set of tools for lexical and syntactical analysis written in pure PHP.

Welcome to Dissect! master - this branch always contains the last stable version. develop - the unstable development branch. Dissect is a set of tools

Jakub LΓ©dl 221 Nov 29, 2022
A project to add Psalm support for Drupal for security testing, focused only on taint analysis.

psalm-plugin-drupal A Drupal integration for Psalm focused on security scanning (SAST) taint analysis. Features Stubs for sinks, sources, and sanitize

Samuel Mortenson 38 Aug 29, 2022
A PHP code-quality tool

GrumPHP Sick and tired of defending code quality over and over again? GrumPHP will do it for you! This composer plugin will register some git hooks in

PHPro 3.9k Jan 1, 2023
A tool to automatically fix PHP Coding Standards issues by Dragon Code.

A tool to automatically fix PHP Coding Standards issues by Dragon Code.

The Dragon Code 24 Aug 27, 2022
Phan is a static analyzer for PHP. Phan prefers to avoid false-positives and attempts to prove incorrectness rather than correctness.

Phan is a static analyzer for PHP that prefers to minimize false-positives. Phan attempts to prove incorrectness rather than correctness. Phan looks f

null 5.4k Jan 7, 2023
A static analyzer for PHP version migration

PHP Migration Readme in Chinese δΈ­ζ–‡ This is a static analyzer for PHP version migration and compatibility checking. It can suppose your current code ru

Yuchen Wang 194 Sep 27, 2022
SonarPHP: PHP static analyzer for SonarQube & SonarLint

Code Quality and Security for PHP This SonarSource project is a static code analyser for PHP language used as an extension for the SonarQube platform.

SonarSource 343 Dec 25, 2022
Parse: A Static Security Scanner

Parse: A PHP Security Scanner PLEASE NOTE: This tool is still in a very early stage. The work continues... The Parse scanner is a static scanning tool

psec.io 342 Jan 2, 2023