This is a bug in wordpress. It’s going through a list of lists of stuff in the sidebar, and adding up the lengths of each list. The problem is that the initial sum is NULL rather than 0. Fix is to add ,0 right before the last end paren.
Like so:
$num_widgets = array_reduce( $sidebars_widgets, create_function( '$prev, $curr', 'return $prev+count($curr);' ), 0 );