sirbrillig/phpcs-variable-analysis
A PHPCS sniff to detect problems with variables.
v3.0.0
55M downloads/mo
#576 most downloaded on Packagist
sirbrillig/phpcs-variable-analysis
What this package is like to depend on
Last release 27 days ago
27 Jul 2026
Ships fairly regularly
a new release about every 3 months
Nearly every release is documented
notes for 55 of 57 stable releases
Nothing withdrawn
no release was ever pulled
9 years old
74 releases · first in 2017
4 releases in the last 12 months
see the full history below
Release timeline
70 releases · Nov 2017 to Jul 2026Releases
latest 60 of 74-
v3.0.027 Jul 2026Release notes
Open source →What's Changed
This is a large refactor which greatly increases the speed and accuracy of phpcs-variable-analysis by adding a dependency on phpcsutils.
Dependencies
- Add phpcsutils as a dependency
- Bump minimum phpcs version from 3.5.7 to 3.13.5 (8683965)
Refactoring (using phpcsutils)
- Simplify
getUseIndexForUseImportusingfindContainingOpeningBracket()(948d77f) - Replace
findFunctionCallArgumentscustom loop withPassedParameters::getParameters()(3a0b6e4) - Replace
isConstructorPromotionmanual scan withFunctionDeclarations::getParameters()(5b97e89) - Replace
areAnyConditionsAClassmanual loop withConditions::hasCondition()(f4ac147) - Simplify
getListAssignmentsusingLists::getAssignments(75768da) - Replace
findContainingOpeningBracketwith phpcsutils equivalent (6b1bdda) - Replace
isVariableInsideUnset/isVariableInsideIssetOrEmptywith phpcsutils equivalents (6a30e89) - Simplify arrow function detection by relying on
T_FN(9da451f) - Remove unnecessary
isArrowFunctionblock ingetScopeCloseForScopeOpen(4cc7f35)
Full Changelog: v2.13.0...v3.0.0
-
v3.0.0-beta.1026 Apr 2026 pre-releaseRelease notes
Open source →- Restore version and dependabot updates from 2.x branch (711a32c)
Full Changelog: v3.0.0-beta.9...v3.0.0-beta.10
-
v3.0.0-beta.921 Apr 2026 pre-releaseRelease notes
Open source →What's Changed
This is preparing for a major 3.0 release which adds a dependency on PHPCSUtils. The new version should have the same functionality, fix some subtle bugs, and increase performance by over 2x.
Dependencies
- Add phpcsutils as a dependency
- Bump minimum phpcs version from 3.5.7 to 3.13.5 (8683965)
Refactoring (using phpcsutils)
- Simplify
getUseIndexForUseImportusingfindContainingOpeningBracket()(948d77f) - Replace
findFunctionCallArgumentscustom loop withPassedParameters::getParameters()(3a0b6e4) - Replace
isConstructorPromotionmanual scan withFunctionDeclarations::getParameters()(5b97e89) - Replace
areAnyConditionsAClassmanual loop withConditions::hasCondition()(f4ac147) - Simplify
getListAssignmentsusingLists::getAssignments(75768da) - Replace
findContainingOpeningBracketwith phpcsutils equivalent (6b1bdda) - Replace
isVariableInsideUnset/isVariableInsideIssetOrEmptywith phpcsutils equivalents (6a30e89) - Simplify arrow function detection by relying on
T_FN(9da451f) - Remove unnecessary
isArrowFunctionblock ingetScopeCloseForScopeOpen(4cc7f35)
Full Changelog: v2.13.0...v3.0.0-beta.9
Release notes
Open source →This is preparing for a major 3.0 release which adds a dependency on PHPCSUtils. The new version should have the same functionality, fix some subtle bugs, and increase performance by over 2x.
Dependencies
- Add PHPCSUtils as a dependency.
- Bump minimum PHPCS version from 3.5.7 to 3.13.5.
Refactoring (using PHPCSUtils)
- Simplify
getUseIndexForUseImportusingfindContainingOpeningBracket(). - Replace
findFunctionCallArgumentscustom loop withPassedParameters::getParameters(). - Replace
isConstructorPromotionmanual scan withFunctionDeclarations::getParameters(). - Replace
areAnyConditionsAClassmanual loop withConditions::hasCondition(). - Simplify
getListAssignmentsusingLists::getAssignments. - Replace
findContainingOpeningBracketwith the PHPCSUtils equivalent. - Replace
isVariableInsideUnset/isVariableInsideIssetOrEmptywith PHPCSUtils equivalents. - Simplify arrow function detection by relying on
T_FN. - Remove unnecessary
isArrowFunctionblock ingetScopeCloseForScopeOpen.
-
v3.0.0-beta.823 Nov 2020 pre-releaseNothing published for this version
-
v3.0.0-beta.710 Sep 2020 pre-releaseNothing published for this version
-
v3.0.0-beta.602 Sep 2020 pre-releaseNothing published for this version
-
v3.0.0-beta.524 Aug 2020 pre-releaseNothing published for this version
-
v3.0.0-beta.418 Aug 2020 pre-releaseNothing published for this version
-
v3.0.0-beta.311 Jul 2020 pre-releaseNothing published for this version
-
v3.0.0-beta.210 Jul 2020 pre-releaseNothing published for this version
-
v3.0.0-beta.112 May 2020 pre-releaseNothing published for this version
-
v2.13.030 Sep 2025Release notes
Open source →What's Changed
- Ruleset: update schema URL by @jrfnl in #353
- Update for phpcs 4.0.0 by @sirbrillig in #356
Full Changelog: v2.12.0...v2.13.0
-
v2.12.017 Mar 2025Release notes
Open source →What's Changed
- GH Actions: use the xmllint-validate action runner by @jrfnl in #350
- Accept namespaces in sitePassByRefFunctions by @sirbrillig in #351
Full Changelog: v2.11.22...v2.12.0
Release notes
Open source →- Accept namespaces in
sitePassByRefFunctions(#351). - GH Actions: use the xmllint-validate action runner (#350).
-
v2.11.2206 Jan 2025Release notes
Open source →What's Changed
- Improve phpstan configuration by @szepeviktor in #344
- Add perf-guard github workflow by @sirbrillig in #345
- Allow finding arrow function variables when arrow function is in file scope by @sirbrillig in #347
New Contributors
- @szepeviktor made their first contribution in #344
Full Changelog: v2.11.21...v2.11.22
Release notes
Open source →- Allow finding arrow function variables when the arrow function is in file scope (#347).
- Add perf-guard GitHub workflow (#345).
- Improve PHPStan configuration (#344).
-
v2.11.2102 Dec 2024Release notes
Open source →What's Changed
- Only search for nested arrow functions if necessary by @sirbrillig in #342
Full Changelog: v2.11.20...v2.11.21
-
v2.11.2001 Dec 2024Release notes
Open source →What's Changed
- Support nested arrow functions by @sirbrillig in #334
- Simplify detecting class properties to improve detection for anonymous classes by @sirbrillig in #337
- Handle compact inside arrow functions by @sirbrillig in #339
- Support constructor promotion with namespaced and union typehints by @sirbrillig in #333
Minor Changes
- Composer: prevent a lock file from being created by @jrfnl in #326
- Composer: psalm 5 is out of beta by @jrfnl in #327
- Tests: allow for running on PHPUnit 10/11 by @jrfnl in #328
- GH Actions: PHP 8.4 has been released by @jrfnl in #336
- Run static-analysis Github action on PHP 8.1 by @sirbrillig in #338
Full Changelog: v2.11.19...v2.11.20
Release notes
Open source →- Support nested arrow functions (#334).
- Simplify detecting class properties to improve detection for anonymous classes (#337).
- Handle
compactinside arrow functions (#339). - Support constructor promotion with namespaced and union typehints (#333).
- Various housekeeping: prevent a Composer lock file (#326), Psalm 5 (#327), PHPUnit 10/11 support (#328), PHP 8.4 in CI (#336), and run static analysis on PHP 8.1 (#338).
-
v2.11.1926 Jun 2024Release notes
Open source →What's Changed
- GH Actions: work around intermittent apt-get errors by @jrfnl in #322
- fix: Process variable before the end of scope by @biinari in #324
New Contributors
Full Changelog: v2.11.18...v2.11.19
Release notes
Open source →- Fix: process variable before the end of scope (#324).
- GH Actions: work around intermittent apt-get errors (#322).
-
v2.11.1813 Apr 2024Release notes
Open source →What's Changed
- Switch to PHPCSStandards/PHP_CodeSniffer by @jrfnl in #315
- Make sure that recursive search of list assignments stays inside them by @sirbrillig in #318
- Fix nullable constructor promotion detection by @sirbrillig in #321
Full Changelog: v2.11.17...v2.11.18
Release notes
Open source →- Switch to PHPCSStandards/PHP_CodeSniffer (#315).
- Make sure that recursive search of list assignments stays inside them (#318).
- Fix nullable constructor promotion detection (#321).
-
v2.11.18-beta.2no date pre-releaseNothing published for this version
-
v2.11.18-beta.124 Mar 2024 pre-releaseNothing published for this version
-
v2.11.1705 Aug 2023 -
v2.11.1631 Mar 2023 -
v2.11.1531 Mar 2023 -
v2.11.1430 Mar 2023 -
v2.11.1330 Mar 2023 -
v2.11.1213 Mar 2023 -
v2.11.1112 Mar 2023 -
v2.11.1005 Jan 2023Release notes
Open source →- Composer: allow for the 1.0.0 version of the Composer PHPCS plugin (#287).
-
v2.11.905 Oct 2022Release notes
Open source →- Prevent detecting static closures when looking for static variables (#281).
-
v2.11.808 Sep 2022 -
v2.11.716 Aug 2022Release notes
Open source →- Place static arrow function body outside of scope on static declaration check (#276). Fixes a
staticvariable regression from #267.
- Place static arrow function body outside of scope on static declaration check (#276). Fixes a
-
v2.11.615 Aug 2022Release notes
Open source →Bug fix release for two regressions caused by the new static function variable scanning added in #267.
- Ignore function call arguments on static declarations processing (#273).
- Fix scanning for static variables near start of file (#274).
-
v2.11.513 Aug 2022Release notes
Open source →- Allow
forloop increment expression to use a variable defined inside the loop (#262). - Support constructor promotion (#266).
- Improve static declaration checks (#267).
- Handle inline
iflist destructure (#268). - Remove
php_errormsgfrom superglobals list (#269). - Ignore unused parameters when a function in an abstract class is empty (#270).
- Allow
-
v2.11.413 Jun 2022 -
v2.11.321 Feb 2022 -
v2.11.206 Jul 2021 -
v2.11.118 Jun 2021Release notes
Open source →- Allow parsing mixed HTML and PHP (#234, #236).
- Ignore double assignment by reference if the second is inside a condition (#235).
-
v2.11.009 Mar 2021Release notes
Open source →- Start inline block scope at end of condition rather than at keyword (#230).
- Add
allowUnusedVariablesInFileScopeoption (#229).
-
v2.10.3-beta.1no date pre-releaseNothing published for this version
-
v2.10.208 Jan 2021Release notes
Open source →- Treat writing to a by-reference
foreachloop variable as a read (#221). - Properly detect variables used in quotes inside arrow functions (#222).
- Treat writing to a by-reference
-
v2.10.2-beta.130 Dec 2020 pre-releaseNothing published for this version
-
v2.10.112 Dec 2020Release notes
Open source →- Performance: only check one parent for recursive list assignment (#218). In at least one example file this brought the speed from 7 minutes down to 0.3 seconds.
-
v2.10.023 Nov 2020Release notes
Open source →A large release that backports nearly all the improvements made on the 3.0 branch to the 2.x line, with the major exception of adding PHPCSUtils as a dependency.
Notable changes since 2.9:
- Fix
array_walkpass-by-reference in 2.x (#216). - Support for PHP 7.4 arrow functions (#179).
- Rewritten and more accurate scope detection.
- Allow undefined variables inside
issetandempty(#204). - Fix error in closures with namespace separators (#197).
- Fix complex default arguments (#198).
- Handle inline
if/else(#199). - Add
allowUndefinedVariablesInFileScopeoption (#193). - Add
allowUnusedVariablesBeforeRequireoption (#196). - Support global scope (#190).
- Add
validUndefinedVariableRegexpoption (#173). - Refactor and clean up reference variables (#187).
- Add special cases for variables used in
elseblocks (#189).
Note: this release intentionally excludes breaking changes from the 3.0 branch, namely replacing
UnusedVariablewithUnusedParameterfor parameters (#195) and adding sniff codes for the array assignment shortcut (#205). - Fix
-
v2.10.0-beta.3no date pre-releaseNothing published for this version
-
v2.10.0-beta.110 Nov 2020 pre-releaseNothing published for this version
-
v2.9.007 Oct 2020Release notes
Open source →Backports some 3.x features to the 2.x line.
- Add
allowUnusedVariablesBeforeRequireoption (originally #196). - Add
allowUndefinedVariablesInFileScopeoption (originally #193).
- Add
-
v2.8.311 Jul 2020 -
v2.8.225 May 2020Release notes
Open source →A backport of the bugfixes from 3.0.0-beta.1 into the 2.x version without any of the PHPCSUtils changes.
- Fix comment tolerance for many sniffs.
- Clean up package structure.
- Only allow unused values in associative
foreachloops with option (#167). - Fix unused-before-used detection (#171).
-
v2.8.2-beta.1no date pre-releaseNothing published for this version
-
v2.8.111 Feb 2020Release notes
Open source →A small bug fix release with test and package clean-up.
- Make assignment of a reference variable be considered a use (#128).
- Bug fix: false negative unused var (#120).
- Bug fix:
$thisin nested function declaration (#119). - Bug fix: recognize use of
self/staticwithin an anonymous class (#110). - PHPStan: document run parameters in project ruleset (#122).
- Composer: update PHPCS Composer plugin dependency (#121), move PHPCS dependency to
require(#106), update DealerDirect Composer plugin requirement (#112). - Documentation: minor fixes (#123).
- Tests: simplify the PHPCS setup method (#115), allow them to work cross-platform (#108), add testsuite name to PHPUnit config (#113).
- Remove stray
composer.lockfile (#117). - Composer: make the PHPUnit requirements more flexible (#114).
- PHPCS: document run parameters in project ruleset (#107).
-
v2.8.010 Oct 2019Release notes
Open source →- Add
apcu_*functions togetPassByReferenceFunctions(#103). - Add sniff codes to README (#100).
- Mention phpcs-changed in README (#97).
- Update README to include PHPStan and linting (#96).
- Refactor methods to have nullable return types (#95).
- Tests: make sure fixtures are valid PHP.
- Add
-
v2.7.024 Jun 2019Release notes
Open source →- Consider
get_defined_vars()to be a read (#92). - Use static analysis to remove edge case bugs (#94).
- Consider
-
v2.6.410 May 2019 -
v2.6.310 May 2019Release notes
Open source →- Downgrade CircleCI image to PHP 5.6 (#86). Fixes a PHP 5.6 regression introduced in 2.6.2 and corrects the Composer minimum PHP version.
-
v2.6.222 Apr 2019 -
v2.6.101 Apr 2019Release notes
Open source →- Improve check for static var defs inside functions (#80).
- Allow
selfandstaticreferences in a trait (#76). - Add checks for class properties (#77).
-
v2.6.015 Feb 2019Release notes
Open source →- Enable
allowUnusedForeachVariablesandallowUnusedCaughtExceptions(#73).
- Enable
-
v2.5.008 Feb 2019Release notes
Open source →- Add ignore unused
foreachoption (#66). - Allow
selfwithin class method closures (#70). - Add
allowWordPressPassByRefFunctionsoption (#69). - Document site pass by ref (#71).
- Add ignore unused
-
v2.4.002 Jan 2019Release notes
Open source →- Handle variable class static refs (#63).
- Ignore numeric variables (#61).
- Make
allowUnusedParametersBeforeUseddefault to true (#59).
-
v2.3.021 Dec 2018