It often happens to me to handle data that can be either an array or a null variable and to feed some foreach with these data.
foreach
$values = get_val
$values = get_values(); foreach ((array) $values as $value){ ... }
Problem is always null and Casting is in fact the cleaning solution.