Problem
Using PHP8, both simulation and execution of the deletion process lead to TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given
Solution
In order to run with PHP8, arguments of array functions count() and array_filter() need to be casted to arrays.