-
-
Notifications
You must be signed in to change notification settings - Fork 863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
filter_var_array
with a mixed
argument results in a fatal error
#9178
Closed
Comments
daniel-calderini
changed the title
Apr 12, 2023
filter_var_array
with a mixed
filter_var_array
with a mixed
argument
daniel-calderini
changed the title
Apr 12, 2023
filter_var_array
with a mixed
argumentfilter_var_array
with a mixed
argument results in a fatal error
/cc @zonuexe Please send a PR with a fix. Personally I'd fix the code like this to make it safe and not crash diff --git a/src/Type/Php/FilterVarArrayDynamicReturnTypeExtension.php b/src/Type/Php/FilterVarArrayDynamicReturnTypeExtension.php
index ac57eb12c..b2ca7f42c 100644
--- a/src/Type/Php/FilterVarArrayDynamicReturnTypeExtension.php
+++ b/src/Type/Php/FilterVarArrayDynamicReturnTypeExtension.php
@@ -78,9 +78,6 @@ class FilterVarArrayDynamicReturnTypeExtension implements DynamicFunctionReturnT
$addEmpty = $addEmptyType === null || $addEmptyType->isTrue()->yes();
$valueTypesBuilder = ConstantArrayTypeBuilder::createEmpty();
- $inputTypesMap = [];
- $optionalKeys = [];
-
if ($filterArgType instanceof ConstantIntegerType) {
if ($inputConstantArrayType === null) {
$isList = $inputArrayType->isList()->yes();
@@ -148,6 +145,9 @@ class FilterVarArrayDynamicReturnTypeExtension implements DynamicFunctionReturnT
}
} else {
$optionalKeys = $filterKeysList;
+ if (count($inputArrayType->getArrays()) !== 1) {
+ return null;
+ }
$inputTypesMap = array_fill_keys($optionalKeys, $inputArrayType->getArrays()[0]->getItemType());
}
}
But it infers the call to be |
Thanks for the report, I'll start fixing it. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Bug report
Starting with version 1.10.12, the following code snippet creates a fatal error:
https://phpstan.org/r/432b5663-9303-4742-969b-f4ac0a168e68
Using version 1.10.11 (or lower), or using
array
type for the$data
argument fixes the fatal error:https://phpstan.org/r/4906b331-8a8d-45c3-860b-2d7039afa990
The text was updated successfully, but these errors were encountered: