Skip to content

Conversation

@andyexeter
Copy link
Contributor

@andyexeter andyexeter commented Nov 15, 2023

The callback parameter of array_filter has been nullable since PHP 8.0 but PHPStan doesn't currently allow it:

https://phpstan.org/r/307000c9-843b-42af-9910-baa02ec72f2f

@andyexeter
Copy link
Contributor Author

I'm not sure why the tests are failing. All I did was copy the signature from the main functionMap.php file and add |null to the callback signature.

@ondrejmirtes
Copy link
Member

Please reproduce your problem in CallToFunctionParametersRuleTest. You'll find that it will still most likely fail.

array_filter is a special function. You need to add NullType here too:

new CallableType(
$arrayFilterParameters ?? [
new DummyParameter('item', $scope->getIterableValueType($scope->getType($args[0]->value)), false, PassedByReference::createNo(), false, null),
],
new MixedType(),
false,
),
(create new UnionType of that CallableType and new NullType).

Please disregard the irrelevant failures.

@andyexeter
Copy link
Contributor Author

@ondrejmirtes I think this is ready for review, the failing tests appear unrelated.

@ondrejmirtes ondrejmirtes merged commit 8d460ac into phpstan:1.10.x Nov 17, 2023
@ondrejmirtes
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants