Phan is a static analyzer for PHP. Phan prefers to avoid false-positives and attempts to prove incorrectness rather than correctness.
If you are migrating from Phan 4, it may be useful to set up or update a Phan baseline file to catch issues such as nullable type mismatches.
https://github.com/phan/phan/wiki/Tutorial-for-Analyzing-a-Large-Sloppy-Code-Base has other advice on setting up suppressions.
For example, Phan is now more consistently warning about nullable arguments (i.e. both \X|null
and ?\X
) in a few cases where it may have not warned about passing \X|null
to a function that expects a non-null type.
If you are using plugins for Phan 4 that are not part of Phan itself, they may have issues in Phan 5 due to additional required parameters being added to many of Phan's methods.
See the changelog for other changes in the previous alpha releases: https://github.com/phan/phan/blob/5.0.0/NEWS.md
Warn about implicitly nullable parameter intersection types (function(A&B $paramName = null)
) being a compile error.
New issue type: PhanTypeMismatchDefaultIntersection
Emit PhanTypeMismatchArgumentSuperType
instead of PhanTypeMismatchArgument
when passing in an object supertype (e.g. ancestor class) of an object instead of a subtype.
Emit PhanTypeMismatchReturnSuperType
instead of PhanTypeMismatchReturn
when returning an object supertype (e.g. ancestor class) of an object instead of a subtype.
Phan 5 starts warning about ancestor classes being incompatible argument or return types in cases where it previously allowed it. (#4413)
This is the unstable branch for alpha releases of Phan 5. Planned/remaining work is described in https://github.com/phan/phan/issues/4413
If you are migrating from Phan 4, it may be useful to set up or update a Phan baseline file to catch issues such as nullable type mismatches.
https://github.com/phan/phan/wiki/Tutorial-for-Analyzing-a-Large-Sloppy-Code-Base has other advice on setting up suppressions.
For example, Phan is now more consistently warning about nullable arguments (i.e. both \X|null
and ?\X
) in a few cases where it may have not warned about passing \X|null
to a function that expects a non-null type.
If you are using plugins that are not part of Phan itself, they may have issues in Phan 5 due to additional required methods being added to many of Phan's methods.
PhanSyntaxEnumCaseExpectedValue
, PhanSyntaxEnumCaseUnexpectedValue
, PhanTypeUnexpectedEnumCaseType
ReturnTypeWillChange
Phan 5 introduces support for intersection types, and improves the accuracy of type casting checks and type inference to catch more issues.
This is the unstable branch for alpha releases of Phan 5. Planned/remaining work is described in https://github.com/phan/phan/issues/4413
If you are migrating from Phan 4, it may be useful to set up or update a Phan baseline file to catch issues such as nullable type mismatches.
https://github.com/phan/phan/wiki/Tutorial-for-Analyzing-a-Large-Sloppy-Code-Base has other advice on setting up suppressions.
For example, Phan is now more consistently warning about nullable arguments (i.e. both \X|null
and ?\X
) in a few cases where it may have not warned about passing \X|null
to a function that expects a non-null type.
If you are using plugins that are not part of Phan itself, they may have issues in Phan 5 due to additional required methods being added to many of Phan's methods.
new
expressions in php 8.1 readonly property modifier (#4460)PhanTypeInvalidArrayKey
and PhanTypeInvalidArrayKeyValue
for invalid array key literal types or values.PhanTypeMissingReturn
/PhanPluginAlwaysReturnMethod
for method with phpdoc return type of @return never
Stringable
to allowed types for sprintf variadic arguments. This currently requires explicitly implementing Stringable. (#4466)The Phan 5 release line (currently in alpha) will support PHP 8.1 syntax and new features such as intersection types
Don't emit PhanCompatibleNonCapturingCatch
when minimum_target_php_version
is '8.0'
or newer. (#4433)
Stop ignoring @return null
and @param null $paramName
in phpdoc. (#4453)
Stop special casing @param null
now that Phan allows many other literal types in param types.
Phan 5 introduces support for intersection types, and improves the accuracy of type casting checks and type inference to catch more issues.
This is the unstable branch for alpha releases of Phan 5. Planned/remaining work is described in https://github.com/phan/phan/issues/4413
If you are migrating from Phan 4, it may be useful to set up or update a Phan baseline file to catch issues such as nullable type mismatches.
https://github.com/phan/phan/wiki/Tutorial-for-Analyzing-a-Large-Sloppy-Code-Base has other advice on setting up suppressions.
For example, Phan is now more consistently warning about nullable arguments (i.e. both \X|null
and ?\X
) in a few cases where it may have not warned about passing \X|null
to a function that expects a non-null type.
If you are using plugins that are not part of Phan itself, they may have issues in Phan 5 due to additional required methods being added to many of Phan's methods.
<=
PhanAccessOverridesFinalConstant
when overriding a final class constant. (#4436)PhanCompatibleFinalClassConstant
if class constants have the final modifier in codebases supporting a minimum target php version older than 8.1 (#4436)var_representation
/polyfill for generating representations of values in issue messages.static fn
declared in an instance method. (#4336)Phan 5 introduces support for intersection types, and improves the accuracy of type casting checks and type inference to catch more issues.
This is the unstable branch for alpha releases of Phan 5. Planned/remaining work is described in https://github.com/phan/phan/issues/4413
If you are migrating from Phan 4, it may be useful to set up or update a Phan baseline file to catch issues such as nullable type mismatches.
https://github.com/phan/phan/wiki/Tutorial-for-Analyzing-a-Large-Sloppy-Code-Base has other advice on setting up suppressions.
For example, Phan is now more consistently warning about nullable arguments (i.e. both \X|null
and ?\X
) in a few cases where it may have not warned about passing \X|null
to a function that expects a non-null type.
If you are using plugins that are not part of Phan itself, they may have issues in Phan 5 due to additional required methods being added to many of Phan's methods.
instanceof
PhanImpossibleIntersectionType
PhanPossiblyUndeclaredPropertyOfClass
PhanPossiblyUndeclaredProperty*
)@template-covariant T
as an alias of @template T
- Previously, that tag was not parsed and T
would be treated like a (probably undeclared) classlike name. (#4432)CodeBase
instance. This will affect third party plugins.--language-server-min-diagnostic-delay-ms
.Partially support php 8.1 enums (#4313) (infer the real type is the class type, that they cannot be instantiated, that enum values cannot be reused, and that class constants will exist for enum cases)
New issue types: PhanReusedEnumCaseValue
, PhanTypeInstantiateEnum
, PhanTypeInvalidEnumCaseType
, PhanSyntaxInconsistentEnum
,
PhanInstanceMethodWithNoEnumCases
, PhanInstanceMethodWithNoEnumCases
, PhanEnumCannotHaveProperties
, PhanUnreferencedEnumCase
,
PhanEnumForbiddenMagicMethod
.
Support php 7.4 covariant return types and contravariant parameter types when the configured or inferred minimum_target_php_version
is '7.4'
or newer (#3795)
Add initial support for the php 8.1 never
type (in real return types and phpdoc). (#4380)
Also add support for the phpdoc aliases no-return
, never-return
, and never-returns
Support casting iterable<K, V>
to Traversable<K, V>
with is_object
or !is_array
checks
Detect more types of expressions that never return when inferring types (e.g. when analyzing ?:
, ??
operators)
Use php 8.1's tentative return types from reflection (hasTentativeReturnType
, getTentativeReturnType
) to assume real return types of internal functions/methods (#4400)
This can be disabled by setting use_tentative_return_type
to false
(e.g. when using subclasses of internal classes that return incompatible types).
Warn about modifying properties of classes that are immutable at runtime (enums, internal classes such as \Closure
and \WeakRef
, etc.) (#4313)
New issue type: PhanTypeModifyImmutableObjectProperty
Infer that functions with a return type of never
(or phpdoc aliases such as no-return
) are unreachable when performing control flow analysis.
This can be disabled by setting dead_code_detection_treat_never_type_as_unreachable
to false
Note that control flow is only affected when UseReturnValuePlugin
is enabled.
UseReturnValuePlugin
, also start warning about when using the result of an expression that evaluates to never
New issue types: PhanUseReturnValueOfNever
As part of the work on php 7.4 contravariant parameter types,
don't automatically inherit inferred parameter types from ancestor classlikes when (1) there is no @param
tag with a type for the parameter on the overriding method and (2) the ancestor parameter types are a subtype of the real parameter types unless
@inheritDoc
is used.array<string,mixed>
that is a specialization of an array type.
If you want to indicate that the overriding method can be any array type, add @param array $paramName
.Change composer.json dependency on composer/xdebug-handler
from ^2.0
to ^1.1|2.0
to avoid conflicting with other libraries or applications that depend on xdebug-handler 1.x (#4382)
Support parsing multiple declare directives in the polyfill/fallback parser (#4160)
non-null-mixed
and null
(#4388, #4391)PhanCompatibleSerializeInterfaceDeprecated
when a class implements Serializable without also implementing the __serialize
and __unserialize
methods as well. (#4387)
PHP 8.1 deprecates the Serializable
interface when __serialize
and __unserialize
aren't also implemented to be used instead of serialize
/unserialize
.__serialize
/__unserialize
in Phan itself in places that use Serializable
.Phan\Language\Type
to account for changes in static variable inheritance in php 8.1. (#4379)?T
to be used in parameter/property types with @template T
(#4388)--doc-comment
flag on tool/make_stubs
to emit the doc comments Phan
is using for internal elements along with the stubs.
(these are the doc comments Phan would use for hover text in the language server)target_php_version
and minimum_target_php_version
to be 8.1 or newer.minimum_target_php_version
is '8.1' or newer.array_is_list(array $array): bool
conditional and its negation. (#4348)ConfigPluginSet
. This is useful for unit testing stateless plugins which declare the plugin class in the same file returning the plugin instance. (#4352)