phpstan

phpstanMIT活跃维护

PHP 静态分析工具,不用运行代码就能扫出类型错误和潜在 bug,适合在 CI 里给 PHP 项目做质量把关。

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

2.3.5发布于 2026-11-03 12:17 UTC14,152star971fork同步于 2026-11-10 05:27 UTC

怎么上手

README 里没有找到可直接复制的安装命令

README 里没有找到可直接复制的安装命令,请到 README 或官方文档查看安装方式。

硬件要求

README 没有说明硬件要求。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

这个项目的说明还在生成中,先参考下面「最近发版」和 README。

这个条目还没有人工点评。如果它对你很有用,欢迎到 提交仓库 页写下你的使用经验。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    最近发版

    5 个版本2.3.5
    1. 2.3.5最新正式版2026-11-03 · 2026-11-03 12:17 UTC

      Huge release!

      Auto-fixable rules with --fix. They show up in the on-line playground too:

      Stale ignoreErrors entries and @phpstan-ignore comments can be removed with --fix too:

      Extensions can be registered with attributes instead of .neon file:

      use PHPStan\DependencyInjection\AutowiredService;
      
      #[AutowiredService]
      class MyExtension implements DynamicMethodReturnTypeExtension
      

      Services be migrated automatically with migrate:neon2attributes.

      Major new features 🚀

      • Support for auto-fixable custom rules
        • analyse command now supports --fix and even --fix-ignored (looks at your ignored auto-fixable errors and fixes them too)
        • Auto-fixable errors are marked with 🔧 in the default table output
        • Rules can change AST with RuleErrorBuilder::fixNode() and removeNode(). Learn more
        • After first round of fixes, PHPStan reanalyses the whole codebase again (which is fast thanks to the result cache) and looks if the first round of fixes produced more errors to fix. It ends after 10 rounds in case the fixes cannot agree about the final state of the code.
        • This is a good fit for "coding standard rules", for example if you want to enforce final classes, named arguments etc.
        • It's not a good fit for errors that have multiple possible fixes (most of PHPStan errors do), like type-related errors. PHPStan cannot know whether the accepting or accepted side should correct its type.
      • Selected errors reported by PHPStan are now autofixable
      • Extensions can be registered with attributes on PHP 8.0+ (#6918), #15114
        • Instead of registering services in neon file, you can now use PHP attributes above classes to register them
        • #[AutowiredService], #[NonAutowiredService], #[AutowiredParameter], #[RegisteredRule], #[RegisteredCollector], #[Conditional], #[GenerateFactory], #[ExtensionInterface]
        • [Learn mor
    2. 2.3.42026-10-28 · 2026-10-28 22:40 UTC
      查看更新说明

      Bleeding edge 🔪

      • Reuse the errors of rules on CollectedDataNode from the result cache (#6840), thanks @SanderMuller!
        • CollectedDataNode rules no longer run every time after analysis. Their reported errors are saved and restored from the result cache. PHPStan tracks what collectors each rule queries for data, and re-runs the rule only when the specific collected data change.
        • Some extensions relying on running every time might need updating. Use the new dependency tracking APIs for proper result cache invalidation.

      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 🔧

      Bugfixes 🐛

      Internals 🔍

    3. 2.3.32026-10-27 · 2026-10-27 14:11 UTC
      查看更新说明

      Improvements 🔧

      Bugfixes 🐛

      • Do not let a bootstrap autoloader's exception abort the analysis (#6294), thanks @SanderMuller!
      • Do not delete a container that another process has not journaled yet (#6797), thanks @SanderMuller!
      • Ignore FILTER_THROW_ON_FAILURE bit when the PHP version range only maybe includes PHP 8.5 and the runtime FILTER_FLAG_GLOBAL_RANGE shares it (#6779), #15481, thanks @VincentLanglet and @staabm!
      • Resolve type arguments of generic static types inside the class, in properties and in class constants (#6826), #15378, #12680
      • Do not cache isGeneric() or the class PHPDoc while the class name scope is created (#6726), #15448, thanks @GErpeldinger!
      • Do not reuse name scopes built from the simplified AST for an analysed file (#6833), #15475
      • Unmatched optional group followed by a matched one is '' in preg_match_all() with PREG_SET_ORDER (#6851)
      • MARK in preg_match_all() with PREG_PATTERN_ORDER is an array of marks keyed by match index (#6851)
      • Treat regex assertions as zero-width and groups in negative assertions as never set (#6851)
      • Do not infer preg_match() shapes for duplicate group names outside of separate alternation branches (#6851)
      • Quantified atom that can match empty string does not make the match non-empty (#6851)
      • Parse backreferences and subroutine calls in regexes, do not infer shapes for patterns with subroutine calls (#6851)
      • Do not infer preg_match() shapes for branch reset groups outside of the only top level alternation (#6851)
      • Groups in conditional regex subpatterns are optional and conditional subpatterns might match an empty string (#6851)
      • Fix PHAR scoping of trigger_deprecation(), remove stale scoper patchers (#6857)
      • Keep the expression result alive in the native ReturnHandler (#6852), thanks @SanderMuller!
      • Fix global constant discovery after class name tokens (#6756), #15482, thanks @LubuSeb!
      • Do not use PHPDoc type of overridable class constants as their native type ([#6859](htt
    4. 2.3.22026-10-24 · 2026-10-24 11:37 UTC
      查看更新说明

      Bleeding edge 🔪

      • BackedEnum::tryFrom() and BackedEnum::from() parameter types takes enum-backing type into account (#6790), #11421, thanks @AJenbo!

      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 🔧

      Bugfixes 🐛

      • Preserve property narrowing in match expression results (#6708), #15433, thanks @drewmt!
      • Keep the list flag when a list shape is intersected with an array type (#6717), #15391, thanks @janedbal!
      • Keep the list flag when a list shape is intersected with an array type (#6717), #15391, thanks @janedbal!
      • Check open integer-range bounds for shift-left overflow (#6647), thanks @JanTvrdik!
      • Stop the recursion when an enum case value reads itself (#6731), #15458, thanks @SanderMuller!
      • Do not map mixed nested in invariant type arguments to strict mixed (#6754), #15487, #14002
      • Ask Composer's autoloaders for the file instead of letting them include it (#6431), #15184, thanks @theodorejb!
      • Invalidate the OPcache entries of included files before an autoloader runs in the autoload trap (#6742), thanks @SanderMuller!
      • OversizedArrayBuilder: expand unpacked items into types directly instead of feeding synthesized TypeExpr items to the type callback (#6774), #15510, thanks @VincentLanglet!
      • Read PHP 8.6 thread-safe EG() and CG() through the exported offsets (#6785), #15504
      • Resolve template types of method calls on a concrete generic static return type (#6695), #12680, thanks @pawell67!
      • Keep an explicit key of an unsealed shape as an optional never key when subtracting its offset (#6792), #15428
      • Walk closures in array-literal arg
    5. 2.3.12026-10-08 · 2026-10-08 21:10 UTC
      查看更新说明

      Same performance, smaller package

      We've heard your feedback. PHPStan 2.3.0 was chonky! It weighed 104 MB when downloaded and 268 MB after being unzipped in your vendor/.

      Afer #6703, PHPStan 2.3.1 weighs just under 28 MB when downloaded and 87 MB unzipped.

      Improvements 🔧

      • Ship the turbo extension as a shared core plus a thin extension per PHP version (#6703), #15423
      • Build Linux ZTS turbo binaries for PHP 8.3-8.5 too (#6706), #15422
      • Allow PHP 8.6 in phpstan/turbo (Composer PIE package) (#6705)

      Bugfixes 🐛

      • Keep the openssl cipher probe's warnings inside the probe (#6372), #15176, thanks @SanderMuller!
      • Create the implicit throw point of a constructor on the new expression (#6687), #15396, thanks @janatjak!
      • Read the updated value of consumed prefix mutations (#6692), #15411, thanks @drewmt!
      • Cache a function reflection under the file that declares it (#6698), thanks @SanderMuller!
      • Do not export what is declared inside a function or method body (#6699), thanks @SanderMuller!

      Performance 🏎️

      • Check original type for unresolvable types only when resolved type has one (#6675), thanks @Kocal!
      • Keep the restored result cache out of forked workers' memory (#6686), #15387, thanks @janedbal!
      • Save the result cache when a file has a parse error (#6694), thanks @SanderMuller!

      Internals 🔍

      • Start the cold run of the warm-rewrite test in a new second (#6697), thanks @SanderMuller!

    README 原文

    未翻译

    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 »

    Try out PHPStan on the on-line playground! »

    Sponsors

    Want your logo here? Learn more »

    Gold Sponsors

       

    Silver Sponsors

    Bronze Sponsors

                               

    You can sponsor my open-source work on PHPStan through GitHub Sponsors and also directly.

    One-time donations through Revolut.me are also accepted. To request an invoice, contact me through e-mail.

    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.

    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.