New features(Analysis):
- Emit the stricter issue type
PhanTypeMismatchReturnReal
instead ofPhanTypeMismatchReturn
when Phan infers that the real type of the returned expression is likely to cause a TypeError (accounting forstrict_types
in the file). (#403)
Seeinternal/Issue-Types-Caught-by-Phan.md
for details on when it is thrown. - Emit the stricter issue type
PhanTypeMismatchArgumentReal
instead ofPhanTypeMismatchArgument
when Phan infers that the real type of the argument is likely to cause a TypeError at runtime (#403) - Support php 7.4 typed property groups in the polyfill/fallback parser.
- Warn about passing properties with incompatible types to reference parameters (#3060)
New issue types:PhanTypeMismatchArgumentPropertyReference
,PhanTypeMismatchArgumentPropertyReferenceReal
- Detect redundant conditions such as
is_array($this->array_prop)
on typed properties.
Their values will either be a value of the correct type, or unset. (Reading from unset properties will throw an Error at runtime) - Emit
PhanCompatibleTypedProperty
if the target php version is less than 7.4 but typed properties are used. - Emit
PhanTypeMismatchPropertyReal
instead ofPhanTypeMismatchProperty
if the properties have real types that are incompatible with the inferred type of the assignment. - Stop warning about
(float) $int
being redundant - there are small differences in how ints and floats are treated byserialize
,var_export
,is_int
, etc. - Treat all assignments to
$this->prop
in a scope the same way (for real, dynamic, and magic properties)
Previously, Phan would not track the effects of some assignments to dynamic properties. - Make
unset($this->prop)
make Phan infer that the property is unset in the current scope (and treat it like null) (only affects$this
). (#3025)
EmitPhanPossiblyUnsetPropertyOfThis
if the property is read from without setting it. - Don't emit
PhanTypeArraySuspiciousNull
when array access is used with the null coalescing operator. (#3032) - Don't emit
PhanTypeInvalidDimOffset
when array access is used with the null coalescing operator. (#2123) - Make Phan check for
PhanUndeclaredTypeProperty
suppressions on the property's doc comment, not the class. (#3047) - Make inferred real/phpdoc types for results of division more accurate.
- Improve analysis of for loops and while loops.
Account for the possibility of the loop iteration never occurring. (unless the condition is unconditionally true) - Fix some edge cases that can cause PhanTypeMismatchProperty (#3067, #1867)
If there was a phpdoc or real type, check against that instead when emitting issues. - Analyze assignments to fields of properties of
$this
(e.g.$this->prop[] = 'value';
)
for correctness and for the new type combination. (#3059) - Infer that the
void
should be treated similarly to null
(in addition to existing checks, it's redundant to compare them to null).
Don't warn aboutreturn null;
in functions/methods with phpdoc-only@return void
.
Plugins:
-
Add
StrictComparisonPlugin
, which warns about the following issue types:- Using
in_array
orarray_search
without specifying$strict
. (PhanPluginComparisonNotStrictInCall
) - Using comparison or weak equality operators when both sides are possibly objects. (
PhanPluginComparisonObjectEqualityNotStrict
,PhanPluginComparisonObjectOrdering
)
- Using
-
Don't warn in
EmptyStatementListPlugin
if a TODO/FIXME/"Deliberately empty" comment is seen around the empty statement list. (#3036)
(This may miss some TODOs due tophp-ast
not providing the end line numbers)
The setting'plugin_config' => ['empty_statement_list_ignore_todos' => true]
can be used to make it unconditionally warn about empty statement lists. -
Improve checks for UseReturnValuePlugin for functions where warning depend on their arg count (
call_user_func
,trait
/interface
/class_exists
,preg_match
, etc)
Bug fixes:
- When a typed property has an incompatible default, don't infer the union type from the default. (#3024)
- Don't emit
PhanTypeMismatchProperties
for assignments to dynamic properties. (#3042) - Fix false positive RedundantConditions analyzing properties of
$this
in the local scope. (#3038) - Properly infer that real type is always
int
(or a subtype) after theis_int($var)
condition. - Emit
TypeMismatchUnpack*
for nullable key types of iterables if the union type didn't contain any int/mixed types. (fix logic error)