UnsafeForeachArrayOfStringRule
doesn't report BenevolentUnionType
of (int|string)
(the default for unspecified array keys)
#6534
Labels
Category: Core
Related to internal functionality
Category: Tests
Pertaining to unit / integration tests
Resolution: Fixed
Issue description
BenevolentUnionType
is a very annoying PHPStan feature that suppresses errors when the union is passed to a type that only accepts a subset of its subtypes.e.g.:
int|string
is accepted byint|string
but not byint
and not bystring
(int|string)
is accepted byint|string
,int
, andstring
This is a problem because
(int|string)
is the default array key type when doing@var SomeType[]
, meaning that dozens of potential crash points haven't been reported.This is because
UnsafeForeachArrayOfStringRule
doesn't distinguish between explicit types and implicit ones.Annoyingly, the places where
BenevolentUnionType
has suppressed these errors are the exact places we'd be most concerned about crashes.OS and versions
Crashdump, backtrace or other files
The following is a list of errors that pop up when
UnsafeForeachArrayOfStringRule
is modified to account forBenevolentUnionType
. Unfortunately, many of these are quite annoying to fix, becauseUtils::stringifyKeys()
can't infer types fromBenevolentUnionType
.@var
is also difficult to use in many such cases asis_array()
may overwrite info from@var
.output.txt
The text was updated successfully, but these errors were encountered: