Skip to content
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

Update array_filter signature in PHP 8.0 to allow null as callback #2740

Merged
merged 6 commits into from Nov 17, 2023

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
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
Projects
None yet
2 participants