We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
See https://getrector.com/demo/0c85f61d-5dab-46fb-ae9e-be5c32d5a3f3
<?php class Test { public function __construct( public int $a, public ?int $b) { } } final class DemoFile { public function run() { $a = new Test(3, null); $arr = []; foreach($a as $k => $v) { if($v !== null) { $arr[$k] = $v; } } echo json_encode($arr); } }
SimplifyForeachToArrayFilterRector
Either leave unchanged or possibly something like
$arr = array_filter(iterator_to_array(new \ArrayIterator($a)), fn($v) => $v !== null);
The problem is that array_filter only supports arrays, so the changed code does not run.
The text was updated successfully, but these errors were encountered:
I think it can just be skipped, could you try provide a patch? Verify that foreach iterated data is only ArrayType
Sorry, something went wrong.
samsonasik
Successfully merging a pull request may close this issue.
Bug Report
Minimal PHP Code Causing Issue
See https://getrector.com/demo/0c85f61d-5dab-46fb-ae9e-be5c32d5a3f3
Responsible rules
SimplifyForeachToArrayFilterRector
Expected Behavior
Either leave unchanged or possibly something like
The problem is that array_filter only supports arrays, so the changed code does not run.
The text was updated successfully, but these errors were encountered: