The cast to array happens too late, line 584 and 588 will fail if $params is not an array or doesn't implement the array accessor interface.

Maybe the function signature should use type hinting and require the parameter to be an array?