Skip to content

Upgrading phpstan/phpstan 1 to 2

Breaking1.12.34 → 2.3.7Breaking27Security1Platform1Deprecated4New356Changed643Fixed978Other583

BreakingUpgrade verdict

27 breaking changes and a platform requirement change and a security fix.

  • Every error reported by a custom rule must now include an identifier.
  • Resolves PHP version checks in remaining scope-aware extensions from Scope::getPhpVersion() and forbids injecting PhpVersion into them.
  • A core extension point is now an interface, so code that extended or instantiated the old class must adapt.
  • Extensions implementing TypeSpecifierAwareExtension receive the TypeSpecifier in a different place, which can affect custom extensions.
Top 5 of 33 that need code or config changes

phpstan/phpstan publishes an official migration guide for version 2. It covers more than the release notes do.

**UPGRADING guide** ↗

PHP requirement changed in 2.0.0: ^7.2|^8.0 → ^7.4|^8.0.

Breaking27
Custom rules are now required to provide an identifier.
Resolves PHP version checks in remaining scope-aware extensions from Scope::getPhpVersion() and forbids injecting PhpVersion into them.
Scope::getPhpVersion()PhpVersion
TypeSpecifier becomes an interface instead of a class.
TypeSpecifier
Changes where TypeSpecifier is set into TypeSpecifierAwareExtension.
TypeSpecifierTypeSpecifierAwareExtension
Removes the unreachable branches rules UnreachableIfBranchesRule, UnreachableTernaryElseBranchRule and the unreachable arm error in MatchExpressionRule.
UnreachableIfBranchesRuleUnreachableTernaryElseBranchRuleMatchExpressionRule
Returning plain strings as errors is no longer supported; use RuleErrorBuilder.
RuleErrorBuilder
Adds a PhpVersion parameter to various Type methods.
PhpVersionType
Eliminates the OriginalPropertyTypeExpr virtual node.
OriginalPropertyTypeExpr
Eliminates the GetOffsetValueTypeExpr virtual node.
GetOffsetValueTypeExpr
Eliminates the GetIterableKeyTypeExpr virtual node.
GetIterableKeyTypeExpr
Eliminates the GetIterableValueTypeExpr virtual node.
GetIterableValueTypeExpr
Replaces SpecifiedTypes::normalize() with symbolic alternative-form entries.
SpecifiedTypes::normalize()
Removes callable.nonNativeMethod.
callable.nonNativeMethod
Drops MutatingScope->rememberConstructorScope().
MutatingScope->rememberConstructorScope()
Removes the implicit wildcard in FileExcluder.
FileExcluder
Moves IllegalConstructorMethodCallRule and IllegalConstructorStaticCallRule to phpstan-strict-rules.
IllegalConstructorMethodCallRuleIllegalConstructorStaticCallRule
Makes a few more MutatingScope method parameters required.
MutatingScope
Makes CommandHelper::begin() parameters required.
CommandHelper::begin()
Makes the MethodTag constructor parameter $templateTags required.
MethodTag$templateTags
Makes the InitializerExprTypeResolver constructor parameter $usePathConstantsAsConstantString required.
InitializerExprTypeResolver$usePathConstantsAsConstantString
Makes all parameters of PhpMethodReflectionFactory::create() required.
PhpMethodReflectionFactory::create()
Makes FunctionCallParametersCheck parameters $nodeType and $acceptsNamedArguments required.
FunctionCallParametersCheck$nodeType$acceptsNamedArguments
Makes the $ignorable parameter of MethodParameterComparisonHelper::compare() required.
MethodParameterComparisonHelpercompare()$ignorable
Makes the $dateTimeClass parameter of the DateTimeModifyReturnTypeExtension constructor required.
DateTimeModifyReturnTypeExtension$dateTimeClass
Makes the NativeFunctionReflection constructor parameters required.
NativeFunctionReflection
Renames NewOptimizedDirectorySourceLocator to OptimizedDirectorySourceLocator.
NewOptimizedDirectorySourceLocatorOptimizedDirectorySourceLocator
Refactors the parameters of FunctionCallParametersCheck::check().
FunctionCallParametersCheck::check()
Security1
Prevents ENV var tokens from being leaked by committed DI containers.
Platform1
PHPStan supports running on PHP 8.6 runtime.
Deprecated4
Deprecates ResultCacheMetaExtension.
ResultCacheMetaExtension
Deprecates various getProperty/hasProperty methods and introduces getStaticProperty, hasStaticProperty, getInstanceProperty and getStaticProperty.
getProperty()hasProperty()getStaticProperty()hasStaticProperty()getInstanceProperty()
Deprecates ClassReflection::isSubclassOf(string $className) in favour of ClassReflection::isSubclassOfClass(ClassReflection $class).
ClassReflection::isSubclassOf()ClassReflection::isSubclassOfClass()ClassReflection::is()ReflectionProvider
Deprecates various instanceof *Type checks in favour of new methods on the Type interface.
Type