Index: capabilities.php
===================================================================
--- capabilities.php	(revision 8483)
+++ capabilities.php	(working copy)
@@ -28,7 +28,7 @@
 
 		$this->role_objects = array();
 		$this->role_names =  array();
-		foreach ($this->roles as $role => $data) {
+		foreach ( (array) $this->roles as $role => $data) {
 			$this->role_objects[$role] = new WP_Role($role, $this->roles[$role]['capabilities']);
 			$this->role_names[$role] = $this->roles[$role]['name'];
 		}
@@ -207,7 +207,7 @@
 	}
 
 	function set_role($role) {
-		foreach($this->roles as $oldrole)
+		foreach( (array) $this->roles as $oldrole)
 			unset($this->caps[$oldrole]);
 		if ( !empty($role) ) {
 			$this->caps[$role] = true;
@@ -265,7 +265,7 @@
 		$caps = call_user_func_array('map_meta_cap', $args);
 		// Must have ALL requested caps
 		$capabilities = apply_filters('user_has_cap', $this->allcaps, $caps, $args);
-		foreach ($caps as $cap) {
+		foreach ( (array) $caps as $cap) {
 			//echo "Checking cap $cap<br />";
 			if(empty($capabilities[$cap]) || !$capabilities[$cap])
 				return false;
Index: category-template.php
===================================================================
--- category-template.php	(revision 8483)
+++ category-template.php	(working copy)
@@ -7,7 +7,7 @@
 	$chain = '';
 	// TODO: consult hierarchy
 	$cat_ids = get_all_category_ids();
-	foreach ( $cat_ids as $cat_id ) {
+	foreach ( (array) $cat_ids as $cat_id ) {
 		if ( $cat_id == $id )
 			continue;
 
@@ -84,7 +84,7 @@
 	else
 		$categories = array();
 
-	foreach(array_keys($categories) as $key) {
+	foreach( (array) array_keys($categories) as $key) {
 		_make_cat_compat($categories[$key]);
 	}
 
Index: category.php
===================================================================
--- category.php	(revision 8483)
+++ category.php	(working copy)
@@ -43,7 +43,7 @@
 	$taxonomy = 'category';
 	if ( 'link' == $args['type'] )
 		$taxonomy = 'link_category';
-	$categories = get_terms($taxonomy, $args);
+	$categories = (array) get_terms($taxonomy, $args);
 
 	foreach ( array_keys($categories) as $k )
 		_make_cat_compat($categories[$k]);
Index: classes.php
===================================================================
--- classes.php	(revision 8483)
+++ classes.php	(working copy)
@@ -90,7 +90,7 @@
 
 			// Look for matches.
 			$request_match = $request;
-			foreach ($rewrite as $match => $query) {
+			foreach ( (array) $rewrite as $match => $query) {
 				// Don't try to match against AtomPub calls
 				if ( $req_uri == 'wp-app.php' )
 					break;
@@ -171,7 +171,7 @@
 			}
 		}
 
-		foreach ($this->private_query_vars as $var) {
+		foreach ( (array) $this->private_query_vars as $var) {
 			if (isset($this->extra_query_vars[$var]))
 				$this->query_vars[$var] = $this->extra_query_vars[$var];
 			elseif (isset($GLOBALS[$var]) && '' != $GLOBALS[$var])
@@ -242,7 +242,7 @@
 
 	function build_query_string() {
 		$this->query_string = '';
-		foreach (array_keys($this->query_vars) as $wpvar) {
+		foreach ( (array) array_keys($this->query_vars) as $wpvar) {
 			if ( '' != $this->query_vars[$wpvar] ) {
 				$this->query_string .= (strlen($this->query_string) < 1) ? '' : '&';
 				if ( !is_scalar($this->query_vars[$wpvar]) ) // Discard non-scalars.
@@ -261,7 +261,7 @@
 	function register_globals() {
 		global $wp_query;
 		// Extract updated query vars back into global namespace.
-		foreach ($wp_query->query_vars as $key => $value) {
+		foreach ( (array) $wp_query->query_vars as $key => $value) {
 			$GLOBALS[$key] = $value;
 		}
 
@@ -350,7 +350,7 @@
 		// Return all messages if no code specified.
 		if ( empty($code) ) {
 			$all_messages = array();
-			foreach ( $this->errors as $code => $messages )
+			foreach ( (array) $this->errors as $code => $messages )
 				$all_messages = array_merge($all_messages, $messages);
 
 			return $all_messages;
@@ -534,7 +534,7 @@
 		* if we are displaying all levels, and remaining children_elements is not empty,
 		* then we got orphans, which should be displayed regardless
 	 	*/
-		if ( ( $max_depth == 0 ) && sizeof( $children_elements ) > 0 ) {
+		if ( ( $max_depth == 0 ) && count( $children_elements ) > 0 ) {
 			$empty_array = array();
 			foreach ( $children_elements as $orphan_e )
 				$this->display_element( $orphan_e, $empty_array, 1, 0, $args, $output );
@@ -755,7 +755,7 @@
 
 		$response = '';
 		if ( is_wp_error($data) ) {
-			foreach ( $data->get_error_codes() as $code ) {
+			foreach ( (array) $data->get_error_codes() as $code ) {
 				$response .= "<wp_error code='$code'><![CDATA[" . $data->get_error_message($code) . "]]></wp_error>";
 				if ( !$error_data = $data->get_error_data($code) )
 					continue;
@@ -781,7 +781,7 @@
 		}
 
 		$s = '';
-		if ( (array) $supplemental ) {
+		if ( is_array($supplemental) ) {
 			foreach ( $supplemental as $k => $v )
 				$s .= "<$k><![CDATA[$v]]></$k>";
 			$s = "<supplemental>$s</supplemental>";
@@ -805,7 +805,7 @@
 	function send() {
 		header('Content-Type: text/xml');
 		echo "<?xml version='1.0' standalone='yes'?><wp_ajax>";
-		foreach ( $this->responses as $response )
+		foreach ( (array) $this->responses as $response )
 			echo $response;
 		echo '</wp_ajax>';
 		die();
Index: comment-template.php
===================================================================
--- comment-template.php	(revision 8483)
+++ comment-template.php	(working copy)
@@ -107,7 +107,7 @@
  */
 function get_comment_author_link() {
 	/** @todo Only call these functions when they are needed. Include in if... else blocks */
-	$url    = get_comment_author_url();
+	$url	= get_comment_author_url();
 	$author = get_comment_author();
 
 	if ( empty( $url ) || 'http://' == $url )
@@ -769,4 +769,4 @@
 	echo '</a>';
 }
 
-?>
\ No newline at end of file
+?>
Index: comment.php
===================================================================
--- comment.php	(revision 8483)
+++ comment.php	(working copy)
@@ -51,7 +51,7 @@
 	if ( !empty($mod_keys) ) {
 		$words = explode("\n", $mod_keys );
 
-		foreach ($words as $word) {
+		foreach ( (array) $words as $word) {
 			$word = trim($word);
 
 			// Skip empty lines
@@ -1190,7 +1190,7 @@
 	// http://dummy-weblog.org/post.php
 	// We don't wanna ping first and second types, even if they have a valid <link/>
 
-	foreach ( $post_links_temp[0] as $link_test ) :
+	foreach ( (array) $post_links_temp[0] as $link_test ) :
 		if ( !in_array($link_test, $pung) && (url_to_postid($link_test) != $post_ID) // If we haven't pung it already and it isn't a link to itself
 				&& !is_local_attachment($link_test) ) : // Also, let's never ping local attachments.
 			$test = parse_url($link_test);
Index: cron.php
===================================================================
--- cron.php	(revision 8483)
+++ cron.php	(working copy)
@@ -121,7 +121,7 @@
 	$schedules = wp_get_schedules();
 	foreach ( $crons as $timestamp => $cronhooks ) {
 		if ( $timestamp > time() ) break;
-		foreach ( $cronhooks as $hook => $args ) {
+		foreach ( (array) $cronhooks as $hook => $args ) {
 			if ( isset($schedules[$hook]['callback']) && !call_user_func( $schedules[$hook]['callback'] ) )
 				continue;
 			spawn_cron();
@@ -178,8 +178,8 @@
 
 	$new_cron = array();
 
-	foreach ($cron as $timestamp => $hooks) {
-		foreach ( $hooks as $hook => $args ) {
+	foreach ( (array) $cron as $timestamp => $hooks) {
+		foreach ( (array) $hooks as $hook => $args ) {
 			$key = md5(serialize($args['args']));
 			$new_cron[$timestamp][$hook][$key] = $args;
 		}
Index: feed.php
===================================================================
--- feed.php	(revision 8483)
+++ feed.php	(working copy)
@@ -398,9 +398,9 @@
 	if ( !empty($post->post_password) && (!isset($_COOKIE['wp-postpass_'.COOKIEHASH]) || $_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) )
 		return;
 
-	foreach (get_post_custom() as $key => $val) {
+	foreach ( (array) get_post_custom() as $key => $val) {
 		if ($key == 'enclosure') {
-			foreach ((array)$val as $enc) {
+			foreach ( (array) $val as $enc ) {
 				$enclosure = split("\n", $enc);
 				echo apply_filters('rss_enclosure', '<enclosure url="' . trim(htmlspecialchars($enclosure[0])) . '" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n");
 			}
@@ -430,9 +430,9 @@
 	if ( !empty($post->post_password) && ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) )
 		return;
 
-	foreach (get_post_custom() as $key => $val) {
+	foreach ( (array) get_post_custom() as $key => $val ) {
 		if ($key == 'enclosure') {
-			foreach ((array)$val as $enc) {
+			foreach ( (array) $val as $enc ) {
 				$enclosure = split("\n", $enc);
 				echo apply_filters('atom_enclosure', '<link href="' . trim(htmlspecialchars($enclosure[0])) . '" rel="enclosure" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n");
 			}
@@ -501,4 +501,4 @@
 		. wp_specialchars(stripslashes($_SERVER['REQUEST_URI']), 1);
 }
 
-?>
\ No newline at end of file
+?>
Index: formatting.php
===================================================================
--- formatting.php	(revision 8483)
+++ formatting.php	(working copy)
@@ -708,7 +708,7 @@
 
 function convert_smilies($text) {
 	global $wp_smiliessearch, $wp_smiliesreplace;
-    $output = '';
+	$output = '';
 	if ( get_option('use_smilies') && !empty($wp_smiliessearch) && !empty($wp_smiliesreplace) ) {
 		// HTML loop taken from texturize function, could possible be consolidated
 		$textarr = preg_split("/(<.*>)/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between
Index: functions.php
===================================================================
--- functions.php	(revision 8483)
+++ functions.php	(working copy)
@@ -421,7 +421,7 @@
 		$options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
 	$wpdb->show_errors($show);
 
-	foreach ( $options as $option ) {
+	foreach ( (array) $options as $option ) {
 		// "When trying to design a foolproof system,
 		//  never underestimate the ingenuity of the fools :)" -- Dougal
 		if ( in_array( $option->option_name, array( 'siteurl', 'home', 'category_base', 'tag_base' ) ) )
@@ -777,7 +777,7 @@
 	debug_fwrite( $log, 'Post contents:' );
 	debug_fwrite( $log, $content . "\n" );
 
-	foreach ( $post_links_temp[0] as $link_test ) {
+	foreach ( (array) $post_links_temp[0] as $link_test ) {
 		if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already
 			$test = parse_url( $link_test );
 			if ( isset( $test['query'] ) )
@@ -787,7 +787,7 @@
 		}
 	}
 
-	foreach ( $post_links as $url ) {
+	foreach ( (array) $post_links as $url ) {
 		if ( $url != '' && !$wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $url . '%' ) ) ) {
 			if ( $headers = wp_get_http_headers( $url) ) {
 				$len = (int) $headers['content-length'];
@@ -1007,7 +1007,7 @@
 		$qs[func_get_arg( 0 )] = func_get_arg( 1 );
 	}
 
-	foreach ( $qs as $k => $v ) {
+	foreach ( (array) $qs as $k => $v ) {
 		if ( $v === false )
 			unset( $qs[$k] );
 	}
@@ -1031,7 +1031,7 @@
  */
 function remove_query_arg( $key, $query=false ) {
 	if ( is_array( $key ) ) { // removing multiple keys
-		foreach ( (array) $key as $k )
+		foreach ( $key as $k )
 			$query = add_query_arg( $k, false, $query );
 		return $query;
 	}
@@ -1049,7 +1049,7 @@
 function add_magic_quotes( $array ) {
 	global $wpdb;
 
-	foreach ( $array as $k => $v ) {
+	foreach ( (array) $array as $k => $v ) {
 		if ( is_array( $v ) ) {
 			$array[$k] = add_magic_quotes( $v );
 		} else {
@@ -2329,4 +2329,4 @@
 	return $url;
 }
 
-?>
\ No newline at end of file
+?>
Index: general-template.php
===================================================================
--- general-template.php	(revision 8483)
+++ general-template.php	(working copy)
@@ -426,7 +426,7 @@
 		}
 		if ( $arcresults ) {
 			$afterafter = $after;
-			foreach ( $arcresults as $arcresult ) {
+			foreach ( (array) $arcresults as $arcresult ) {
 				$url	= get_month_link($arcresult->year,	$arcresult->month);
 				$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);
 				if ( $show_post_count )
@@ -447,7 +447,7 @@
 		}
 		if ($arcresults) {
 			$afterafter = $after;
-			foreach ($arcresults as $arcresult) {
+			foreach ( (array) $arcresults as $arcresult) {
 				$url = get_year_link($arcresult->year);
 				$text = sprintf('%d', $arcresult->year);
 				if ($show_post_count)
@@ -468,7 +468,7 @@
 		}
 		if ( $arcresults ) {
 			$afterafter = $after;
-			foreach ( $arcresults as $arcresult ) {
+			foreach ( (array) $arcresults as $arcresult ) {
 				$url	= get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);
 				$date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $arcresult->year, $arcresult->month, $arcresult->dayofmonth);
 				$text = mysql2date($archive_day_date_format, $date);
@@ -492,7 +492,7 @@
 		$arc_w_last = '';
 		$afterafter = $after;
 		if ( $arcresults ) {
-				foreach ( $arcresults as $arcresult ) {
+				foreach ( (array) $arcresults as $arcresult ) {
 					if ( $arcresult->week != $arc_w_last ) {
 						$arc_year = $arcresult->yr;
 						$arc_w_last = $arcresult->week;
@@ -520,7 +520,7 @@
 			$arcresults = $cache[ $key ];
 		}
 		if ( $arcresults ) {
-			foreach ( $arcresults as $arcresult ) {
+			foreach ( (array) $arcresults as $arcresult ) {
 				if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {
 					$url  = get_permalink($arcresult);
 					$arc_title = $arcresult->post_title;
@@ -660,7 +660,7 @@
 		AND post_type = 'post' AND post_status = 'publish'
 		AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
 	if ( $dayswithposts ) {
-		foreach ( $dayswithposts as $daywith ) {
+		foreach ( (array) $dayswithposts as $daywith ) {
 			$daywithpost[] = $daywith[0];
 		}
 	} else {
@@ -681,7 +681,7 @@
 		."AND post_type = 'post' AND post_status = 'publish'"
 	);
 	if ( $ak_post_titles ) {
-		foreach ( $ak_post_titles as $ak_post_title ) {
+		foreach ( (array) $ak_post_titles as $ak_post_title ) {
 
 				$post_title = apply_filters( "the_title", $ak_post_title->post_title );
 				$post_title = str_replace('"', '&quot;', wptexturize( $post_title ));
@@ -748,7 +748,7 @@
 function allowed_tags() {
 	global $allowedtags;
 	$allowed = '';
-	foreach ( $allowedtags as $tag => $attributes ) {
+	foreach ( (array) $allowedtags as $tag => $attributes ) {
 		$allowed .= '<'.$tag;
 		if ( 0 < count($attributes) ) {
 			foreach ( $attributes as $attribute => $limits ) {
@@ -1058,7 +1058,7 @@
 	extract($args, EXTR_SKIP);
 
 	// Who knows what else people pass in $args
-	$total    = (int) $total;
+	$total	= (int) $total;
 	if ( $total < 2 )
 		return;
 	$current  = (int) $current;
Index: kses.php
===================================================================
--- kses.php	(revision 8483)
+++ kses.php	(working copy)
@@ -793,11 +793,11 @@
 function wp_kses_array_lc($inarray) {
 	$outarray = array ();
 
-	foreach ($inarray as $inkey => $inval) {
+	foreach ( (array) $inarray as $inkey => $inval) {
 		$outkey = strtolower($inkey);
 		$outarray[$outkey] = array ();
 
-		foreach ($inval as $inkey2 => $inval2) {
+		foreach ( (array) $inval as $inkey2 => $inval2) {
 			$outkey2 = strtolower($inkey2);
 			$outarray[$outkey][$outkey2] = $inval2;
 		} # foreach $inval
Index: locale.php
===================================================================
--- locale.php	(revision 8483)
+++ locale.php	(working copy)
@@ -190,7 +190,7 @@
 		$this->number_format['thousands_sep'] = ('number_format_thousands_sep' == $trans) ? ',' : $trans;
 
 		// Import global locale vars set during inclusion of $locale.php.
-		foreach ( $this->locale_vars as $var ) {
+		foreach ( (array) $this->locale_vars as $var ) {
 			if ( isset($GLOBALS[$var]) )
 				$this->$var = $GLOBALS[$var];
 		}
Index: pluggable.php
===================================================================
--- pluggable.php	(revision 8483)
+++ pluggable.php	(working copy)
@@ -789,7 +789,7 @@
 	$found = true;
 	while($found) {
 		$found = false;
-		foreach($strip as $val) {
+		foreach( (array) $strip as $val) {
 			while(strpos($location, $val) !== false) {
 				$found = true;
 				$location = str_replace($val, '', $location);
@@ -1562,4 +1562,4 @@
 }
 endif;
 
-?>
\ No newline at end of file
+?>
Index: plugin.php
===================================================================
--- plugin.php	(revision 8483)
+++ plugin.php	(working copy)
@@ -90,7 +90,7 @@
 	if ( !$idx = _wp_filter_build_unique_id($tag, $function_to_check, false) )
 		return false;
 
-	foreach ( array_keys($wp_filter[$tag]) as $priority ) {
+	foreach ( (array) array_keys($wp_filter[$tag]) as $priority ) {
 		if ( isset($wp_filter[$tag][$priority][$idx]) )
 			return $priority;
 	}
Index: post-template.php
===================================================================
--- post-template.php	(revision 8483)
+++ post-template.php	(working copy)
@@ -252,7 +252,7 @@
 function the_meta() {
 	if ( $keys = get_post_custom_keys() ) {
 		echo "<ul class='post-meta'>\n";
-		foreach ( $keys as $key ) {
+		foreach ( (array) $keys as $key ) {
 			$keyt = trim($key);
 			if ( '_' == $keyt{0} )
 				continue;
Index: post.php
===================================================================
--- post.php	(revision 8483)
+++ post.php	(working copy)
@@ -143,11 +143,11 @@
 	if ( $output == OBJECT ) {
 		return $kids;
 	} elseif ( $output == ARRAY_A ) {
-		foreach ( $kids as $kid )
+		foreach ( (array) $kids as $kid )
 			$weeuns[$kid->ID] = get_object_vars($kids[$kid->ID]);
 		return $weeuns;
 	} elseif ( $output == ARRAY_N ) {
-		foreach ( $kids as $kid )
+		foreach ( (array) $kids as $kid )
 			$babes[$kid->ID] = array_values(get_object_vars($kids[$kid->ID]));
 		return $babes;
 	} else {
@@ -1497,7 +1497,7 @@
 	wp_transition_post_status('publish', $old_status, $post);
 
 	// Update counts for the post's terms.
-	foreach ( get_object_taxonomies('post') as $taxonomy ) {
+	foreach ( (array) get_object_taxonomies('post') as $taxonomy ) {
 		$terms = wp_get_object_terms($post_id, $taxonomy, 'fields=tt_ids');
 		wp_update_term_count($terms, $taxonomy);
 	}
@@ -1763,7 +1763,7 @@
 		}
 
 		$trackback_urls = explode(',', $tb_list);
-		foreach($trackback_urls as $tb_url) {
+		foreach( (array) $trackback_urls as $tb_url) {
 				$tb_url = trim($tb_url);
 				trackback($tb_url, stripslashes($post_title), $excerpt, $post_id);
 		}
@@ -1844,7 +1844,7 @@
 	$page_paths = '/' . trim($page_path, '/');
 	$leaf_path  = sanitize_title(basename($page_paths));
 	$page_paths = explode('/', $page_paths);
-	foreach($page_paths as $pathdir)
+	foreach( (array) $page_paths as $pathdir)
 		$full_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir);
 
 	$pages = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_name = %s AND (post_type = 'page' OR post_type = 'attachment')", $leaf_path ));
@@ -1905,7 +1905,7 @@
  */
 function &get_page_children($page_id, $pages) {
 	$page_list = array();
-	foreach ( $pages as $page ) {
+	foreach ( (array) $pages as $page ) {
 		if ( $page->post_parent == $page_id ) {
 			$page_list[] = $page;
 			if ( $children = get_page_children($page->ID, $pages) )
@@ -1931,7 +1931,7 @@
  */
 function get_page_hierarchy($posts, $parent = 0) {
 	$result = array ( );
-	if ($posts) { foreach ($posts as $post) {
+	if ($posts) { foreach ( (array) $posts as $post) {
 		if ($post->post_parent == $parent) {
 			$result[$post->ID] = $post->post_name;
 			$children = get_page_hierarchy($posts, $post->ID);
@@ -2946,7 +2946,7 @@
 			$cache[$id] = array();
 	}
 
-	foreach ( array_keys($cache) as $post)
+	foreach ( (array) array_keys($cache) as $post)
 		wp_cache_set($post, $cache[$post], 'post_meta');
 
 	return $cache;
Index: query.php
===================================================================
--- query.php	(revision 8483)
+++ query.php	(working copy)
@@ -214,7 +214,7 @@
 
 	$page = (array) $page;
 
-    if ( in_array( $page_obj->ID, $page ) )
+	if ( in_array( $page_obj->ID, $page ) )
 		return true;
 	elseif ( in_array( $page_obj->post_title, $page ) )
 		return true;
@@ -987,7 +987,7 @@
 			}
 			$n = ($q['exact']) ? '' : '%';
 			$searchand = '';
-			foreach((array)$q['search_terms'] as $term) {
+			foreach( (array) $q['search_terms'] as $term) {
 				$term = addslashes_gpc($term);
 				$search .= "{$searchand}(($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}'))";
 				$searchand = ' AND ';
@@ -1012,7 +1012,7 @@
 			$cat_array = preg_split('/[,\s]+/', $q['cat']);
 			$q['cat'] = '';
 			$req_cats = array();
-			foreach ( $cat_array as $cat ) {
+			foreach ( (array) $cat_array as $cat ) {
 				$cat = intval($cat);
 				$req_cats[] = $cat;
 				$in = ($cat > 0);
Index: rewrite.php
===================================================================
--- rewrite.php	(revision 8483)
+++ rewrite.php	(working copy)
@@ -157,7 +157,7 @@
 			global $wp;
 			parse_str($query, $query_vars);
 			$query = array();
-			foreach ( $query_vars as $key => $value ) {
+			foreach ( (array) $query_vars as $key => $value ) {
 				if ( in_array($key, $wp->public_query_vars) )
 					$query[$key] = $value;
 			}
@@ -390,7 +390,7 @@
 		$front = $this->front;
 		preg_match_all('/%.+?%/', $this->permalink_structure, $tokens);
 		$tok_index = 1;
-		foreach ($tokens[0] as $token) {
+		foreach ( (array) $tokens[0] as $token) {
 			if ( ($token == '%post_id%') && ($tok_index <= 3) ) {
 				$front = $front . 'date/';
 				break;
@@ -574,7 +574,7 @@
 	function generate_rewrite_rules($permalink_structure, $ep_mask = EP_NONE, $paged = true, $feed = true, $forcomments = false, $walk_dirs = true, $endpoints = true) {
 		//build a regex to match the feed section of URLs, something like (feed|atom|rss|rss2)/?
 		$feedregex2 = '';
-		foreach ($this->feeds as $feed_name) {
+		foreach ( (array) $this->feeds as $feed_name) {
 			$feedregex2 .= $feed_name . '|';
 		}
 		$feedregex2 = '(' . trim($feedregex2, '|') .  ')/?$';
@@ -589,7 +589,7 @@
 		//build up an array of endpoint regexes to append => queries to append
 		if ($endpoints) {
 			$ep_query_append = array ();
-			foreach ($this->endpoints as $endpoint) {
+			foreach ( (array) $this->endpoints as $endpoint) {
 				//match everything after the endpoint name, but allow for nothing to appear there
 				$epmatch = $endpoint[1] . '(/(.*))?/?$';
 				//this will be appended on to the rest of the query for each dir
@@ -688,7 +688,7 @@
 
 			//do endpoints
 			if ($endpoints) {
-				foreach ($ep_query_append as $regex => $ep) {
+				foreach ( (array) $ep_query_append as $regex => $ep) {
 					//add the endpoints on if the mask fits
 					if ($ep[0] & $ep_mask || $ep[0] & $ep_mask_specific) {
 						$rewrite[$match . $regex] = $index . '?' . $query . $ep[1] . $this->preg_index($num_toks + 2);
@@ -745,7 +745,7 @@
 					$subfeedquery = $subquery . '&feed=' . $this->preg_index(2);
 
 					//do endpoints for attachments
-					if (! empty($endpoint) ) { foreach ($ep_query_append as $regex => $ep) {
+					if ( !empty($endpoint) ) { foreach ( (array) $ep_query_append as $regex => $ep ) {
 						if ($ep[0] & EP_ATTACHMENT) {
 							$rewrite[$sub1 . $regex] = $subquery . '?' . $ep[1] . $this->preg_index(2);
 							$rewrite[$sub2 . $regex] = $subquery . '?' . $ep[1] . $this->preg_index(2);
@@ -893,7 +893,7 @@
 		$rules .= "RewriteBase $home_root\n";
 
 		//add in the rules that don't redirect to WP's index.php (and thus shouldn't be handled by WP at all)
-		foreach ($this->non_wp_rules as $match => $query) {
+		foreach ( (array) $this->non_wp_rules as $match => $query) {
 			// Apache 1.3 does not support the reluctant (non-greedy) modifier.
 			$match = str_replace('.+?', '.+', $match);
 
@@ -914,7 +914,7 @@
 				"RewriteCond %{REQUEST_FILENAME} -d\n" .
 				"RewriteRule ^.*$ - [S=$num_rules]\n";
 
-			foreach ($rewrite as $match => $query) {
+			foreach ( (array) $rewrite as $match => $query) {
 				// Apache 1.3 does not support the reluctant (non-greedy) modifier.
 				$match = str_replace('.+?', '.+', $match);
 
Index: rss.php
===================================================================
--- rss.php	(revision 8483)
+++ rss.php	(working copy)
@@ -534,10 +534,10 @@
 	$rss = new MagpieRSS( $resp->results );
 
 	// if RSS parsed successfully
-	if ( $rss and !$rss->ERROR) {
+	if ( $rss && !$rss->ERROR) {
 
 		// find Etag, and Last-Modified
-		foreach($resp->headers as $h) {
+		foreach( (array) $resp->headers as $h) {
 			// 2003-03-02 - Nicola Asuni (www.tecnick.com) - fixed bug "Undefined offset: 1"
 			if (strpos($h, ": ")) {
 				list($field, $val) = explode(": ", $h, 2);
@@ -843,7 +843,7 @@
 			$rss->items = array_slice( $rss->items, 0, $num_items );
 		}
 
-		foreach ( $rss->items as $item ) {
+		foreach ( (array) $rss->items as $item ) {
 			printf(
 				'<li><a href="%1$s" title="%2$s">%3$s</a></li>',
 				clean_url( $item['link'] ),
@@ -864,7 +864,7 @@
 	$rss = fetch_rss($url);
 	if ( $rss ) {
 		$rss->items = array_slice($rss->items, 0, $num_items);
-		foreach ($rss->items as $item ) {
+		foreach ( (array) $rss->items as $item ) {
 			echo "<li>\n";
 			echo "<a href='$item[link]' title='$item[description]'>";
 			echo htmlentities($item['title']);
@@ -877,4 +877,4 @@
 }
 endif;
 
-?>
\ No newline at end of file
+?>
Index: taxonomy.php
===================================================================
--- taxonomy.php	(revision 8483)
+++ taxonomy.php	(working copy)
@@ -49,7 +49,7 @@
 	$object = (array) $object;
 
 	$taxonomies = array();
-	foreach ( $wp_taxonomies as $taxonomy ) {
+	foreach ( (array) $wp_taxonomies as $taxonomy ) {
 		if ( array_intersect($object, (array) $taxonomy->object_type) )
 			$taxonomies[] = $taxonomy->name;
 	}
@@ -230,7 +230,7 @@
 	if ( !is_array($taxonomies) )
 		$taxonomies = array($taxonomies);
 
-	foreach ( $taxonomies as $taxonomy ) {
+	foreach ( (array) $taxonomies as $taxonomy ) {
 		if ( ! is_taxonomy($taxonomy) )
 			return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
 	}
@@ -425,7 +425,7 @@
 
 	$children = $terms[$term];
 
-	foreach ( $terms[$term] as $child ) {
+	foreach ( (array) $terms[$term] as $child ) {
 		if ( isset($terms[$child]) )
 			$children = array_merge($children, get_term_children($child, $taxonomy));
 	}
@@ -558,7 +558,7 @@
 		$taxonomies = array($taxonomies);
 	}
 
-	foreach ( $taxonomies as $taxonomy ) {
+	foreach ( (array) $taxonomies as $taxonomy ) {
 		if ( ! is_taxonomy($taxonomy) )
 			return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
 	}
@@ -626,7 +626,7 @@
 		$exclude = '';
 		$interms = preg_split('/[\s,]+/',$include);
 		if ( count($interms) ) {
-			foreach ( $interms as $interm ) {
+			foreach ( (array) $interms as $interm ) {
 				if (empty($inclusions))
 					$inclusions = ' AND ( t.term_id = ' . intval($interm) . ' ';
 				else
@@ -643,7 +643,7 @@
 	if ( !empty($exclude) ) {
 		$exterms = preg_split('/[\s,]+/',$exclude);
 		if ( count($exterms) ) {
-			foreach ( $exterms as $exterm ) {
+			foreach ( (array) $exterms as $exterm ) {
 				if (empty($exclusions))
 					$exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' ';
 				else
@@ -721,13 +721,14 @@
 		_pad_term_counts($terms, $taxonomies[0]);
 
 	// Make sure we show empty categories that have children.
-	if ( $hierarchical && $hide_empty ) {
+	if ( $hierarchical && $hide_empty && is_array($terms) ) {
 		foreach ( $terms as $k => $term ) {
 			if ( ! $term->count ) {
 				$children = _get_term_children($term->term_id, $terms, $taxonomies[0]);
-				foreach ( $children as $child )
-					if ( $child->count )
-						continue 2;
+				if( is_array($children) )
+					foreach ( $children as $child )
+						if ( $child->count )
+							continue 2;
 
 				// It really is empty
 				unset($terms[$k]);
@@ -824,7 +825,7 @@
 	if ( is_object($term) )
 		$do_object = true;
 
-	foreach ( $fields as $field ) {
+	foreach ( (array) $fields as $field ) {
 		if ( $do_object )
 			$term->$field = sanitize_term_field($field, $term->$field, $term->term_id, $taxonomy, $context);
 		else
@@ -955,7 +956,7 @@
 	if ( !is_array($taxonomies) )
 		$taxonomies = array($taxonomies);
 
-	foreach ( $taxonomies as $taxonomy ) {
+	foreach ( (array) $taxonomies as $taxonomy ) {
 		$terms = wp_get_object_terms($object_id, $taxonomy, 'fields=tt_ids');
 		$in_terms = "'" . implode("', '", $terms) . "'";
 		$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id IN ($in_terms)", $object_id) );
@@ -1082,7 +1083,7 @@
 	if ( !is_array($taxonomies) )
 		$taxonomies = array($taxonomies);
 
-	foreach ( $taxonomies as $taxonomy ) {
+	foreach ( (array) $taxonomies as $taxonomy ) {
 		if ( ! is_taxonomy($taxonomy) )
 			return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
 	}
@@ -1323,7 +1324,7 @@
 	$tt_ids = array();
 	$term_ids = array();
 
-	foreach ($terms as $term) {
+	foreach ( (array) $terms as $term) {
 		if ( !strlen(trim($term)) )
 			continue;
 
@@ -1587,7 +1588,7 @@
 	static $_deferred = array();
 
 	if ( $do_deferred ) {
-		foreach ( array_keys($_deferred) as $tax ) {
+		foreach ( (array) array_keys($_deferred) as $tax ) {
 			wp_update_term_count_now( $_deferred[$tax], $tax );
 			unset( $_deferred[$tax] );
 		}
@@ -1628,7 +1629,7 @@
 		call_user_func($taxonomy->update_count_callback, $terms);
 	} else {
 		// Default count updater
-		foreach ($terms as $term) {
+		foreach ( (array) $terms as $term) {
 			$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term) );
 			$wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
 		}
@@ -1821,7 +1822,7 @@
  * @param string $taxonomy Optional. Update Term to this taxonomy in cache
  */
 function update_term_cache($terms, $taxonomy = '') {
-	foreach ( $terms as $term ) {
+	foreach ( (array) $terms as $term ) {
 		$term_taxonomy = $taxonomy;
 		if ( empty($term_taxonomy) )
 			$term_taxonomy = $term->taxonomy;
@@ -1896,7 +1897,7 @@
 	if  ( ( 0 != $term_id ) && ! isset($has_children[$term_id]) )
 		return $empty_array;
 
-	foreach ( $terms as $term ) {
+	foreach ( (array) $terms as $term ) {
 		$use_id = false;
 		if ( !is_object($term) ) {
 			$term = get_term($term, $taxonomy);
@@ -1956,7 +1957,7 @@
 
 	$term_items = array();
 
-	foreach ( $terms as $key => $term ) {
+	foreach ( (array) $terms as $key => $term ) {
 		$terms_by_id[$term->term_id] = & $terms[$key];
 		$term_ids[$term->term_taxonomy_id] = $term->term_id;
 	}
@@ -2006,7 +2007,7 @@
 function _update_post_term_count( $terms ) {
 	global $wpdb;
 
-	foreach ( $terms as $term ) {
+	foreach ( (array) $terms as $term ) {
 		$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term ) );
 		$wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
 	}
@@ -2154,4 +2155,4 @@
 	return get_object_taxonomies($post);
 }
 
-?>
\ No newline at end of file
+?>
Index: user.php
===================================================================
--- user.php	(revision 8483)
+++ user.php	(working copy)
@@ -286,7 +286,7 @@
 		if ( $show_option_none )
 			$output .= "\t<option value='-1'>$show_option_none</option>\n";
 
-		foreach ( $users as $user ) {
+		foreach ( (array) $users as $user ) {
 			$user->ID = (int) $user->ID;
 			$_selected = $user->ID == $selected ? " selected='selected'" : '';
 			$output .= "\t<option value='$user->ID'$_selected>" . wp_specialchars($user->$show) . "</option>\n";
@@ -311,7 +311,7 @@
 	$wpdb->show_errors($show);
 
 	if ( $metavalues ) {
-		foreach ( $metavalues as $meta ) {
+		foreach ( (array) $metavalues as $meta ) {
 			$value = maybe_unserialize($meta->meta_value);
 			$user->{$meta->meta_key} = $value;
 		}
Index: widgets.php
===================================================================
--- widgets.php	(revision 8483)
+++ widgets.php	(working copy)
@@ -208,7 +208,7 @@
 		$index = "sidebar-$index";
 	} else {
 		$index = sanitize_title($index);
-		foreach ( $wp_registered_sidebars as $key => $value ) {
+		foreach ( (array) $wp_registered_sidebars as $key => $value ) {
 			if ( sanitize_title($value['name']) == $index ) {
 				$index = $key;
 				break;
@@ -224,7 +224,7 @@
 	$sidebar = $wp_registered_sidebars[$index];
 
 	$did_one = false;
-	foreach ( $sidebars_widgets[$index] as $id ) {
+	foreach ( (array) $sidebars_widgets[$index] as $id ) {
 		$params = array_merge(
 			array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ),
 			(array) $wp_registered_widgets[$id]['params']
@@ -274,9 +274,9 @@
 function is_dynamic_sidebar() {
 	global $wp_registered_widgets, $wp_registered_sidebars;
 	$sidebars_widgets = get_option('sidebars_widgets');
-	foreach ( $wp_registered_sidebars as $index => $sidebar ) {
+	foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) {
 		if ( count($sidebars_widgets[$index]) ) {
-			foreach ( $sidebars_widgets[$index] as $widget )
+			foreach ( (array) $sidebars_widgets[$index] as $widget )
 				if ( array_key_exists($widget, $wp_registered_widgets) )
 					return true;
 		}
@@ -297,9 +297,9 @@
 
 	switch ( $sidebars_widgets['array_version'] ) {
 		case 1 :
-			foreach ( $sidebars_widgets as $index => $sidebar )
+			foreach ( (array) $sidebars_widgets as $index => $sidebar )
 			if ( is_array($sidebar) )
-			foreach ( $sidebar as $i => $name ) {
+			foreach ( (array) $sidebar as $i => $name ) {
 				$id = strtolower($name);
 				if ( isset($wp_registered_widgets[$id]) ) {
 					$_sidebars_widgets[$index][$i] = $id;
@@ -338,7 +338,7 @@
 			$sidebars = array_keys( $wp_registered_sidebars );
 			if ( !empty( $sidebars ) ) {
 				// Move the known-good ones first
-				foreach ( $sidebars as $id ) {
+				foreach ( (array) $sidebars as $id ) {
 					if ( array_key_exists( $id, $sidebars_widgets ) ) {
 						$_sidebars_widgets[$id] = $sidebars_widgets[$id];
 						unset($sidebars_widgets[$id], $sidebars[$id]);
@@ -373,7 +373,7 @@
 
 	$defaults = array();
 
-	foreach ( $wp_registered_sidebars as $index => $sidebar )
+	foreach ( (array) $wp_registered_sidebars as $index => $sidebar )
 		$defaults[$index] = array();
 
 	return $defaults;
@@ -635,7 +635,7 @@
 		else
 			$this_sidebar = array();
 
-		foreach ( $this_sidebar as $_widget_id ) {
+		foreach ( (array) $this_sidebar as $_widget_id ) {
 			if ( 'wp_widget_text' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
 				$widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
 				if ( !in_array( "text-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed.
@@ -683,7 +683,7 @@
 	$name = __('Text');
 
 	$id = false;
-	foreach ( array_keys($options) as $o ) {
+	foreach ( (array) array_keys($options) as $o ) {
 		// Old widgets can have null values for some reason
 		if ( !isset($options[$o]['title']) || !isset($options[$o]['text']) )
 			continue;
@@ -729,13 +729,13 @@
 
 <script type='text/javascript'>
 /* <![CDATA[ */
-    var dropdown = document.getElementById("cat");
-    function onCatChange() {
+	var dropdown = document.getElementById("cat");
+	function onCatChange() {
 		if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
 			location.href = "<?php echo get_option('home'); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
 		}
-    }
-    dropdown.onchange = onCatChange;
+	}
+	dropdown.onchange = onCatChange;
 /* ]]> */
 </script>
 
@@ -777,7 +777,7 @@
 		else
 			$this_sidebar = array();
 
-		foreach ( $this_sidebar as $_widget_id ) {
+		foreach ( (array) $this_sidebar as $_widget_id ) {
 			if ( 'wp_widget_categories' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
 				$widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
 				if ( !in_array( "categories-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed.
@@ -852,7 +852,7 @@
 	$name = __( 'Categories' );
 
 	$id = false;
-	foreach ( array_keys($options) as $o ) {
+	foreach ( (array) array_keys($options) as $o ) {
 		// Old widgets can have null values for some reason
 		if ( !isset($options[$o]['title']) )
 			continue;
@@ -986,7 +986,7 @@
 		<?php echo $before_widget; ?>
 			<?php echo $before_title . $title . $after_title; ?>
 			<ul id="recentcomments"><?php
-			if ( $comments ) : foreach ($comments as $comment) :
+			if ( $comments ) : foreach ( (array) $comments as $comment) :
 			echo  '<li class="recentcomments">' . sprintf(__('%1$s on %2$s'), get_comment_author_link(), '<a href="'. get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
 			endforeach; endif;?></ul>
 		<?php echo $after_widget; ?>
@@ -1117,7 +1117,7 @@
 	if ( is_array( $rss->items ) && !empty( $rss->items ) ) {
 		$rss->items = array_slice($rss->items, 0, $items);
 		echo '<ul>';
-		foreach ($rss->items as $item ) {
+		foreach ( (array) $rss->items as $item ) {
 			while ( strstr($item['link'], 'http') != $item['link'] )
 				$item['link'] = substr($item['link'], 1);
 			$link = clean_url(strip_tags($item['link']));
@@ -1191,7 +1191,7 @@
 		$options = array();
 
 	$urls = array();
-	foreach ( $options as $option )
+	foreach ( (array) $options as $option )
 		if ( isset($option['url']) )
 			$urls[$option['url']] = true;
 
@@ -1204,7 +1204,7 @@
 		else
 			$this_sidebar = array();
 
-		foreach ( $this_sidebar as $_widget_id ) {
+		foreach ( (array) $this_sidebar as $_widget_id ) {
 			if ( 'wp_widget_rss' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
 				$widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
 				if ( !in_array( "rss-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed.
@@ -1349,7 +1349,7 @@
 	$name = __('RSS');
 
 	$id = false;
-	foreach ( array_keys($options) as $o ) {
+	foreach ( (array) array_keys($options) as $o ) {
 		// Old widgets can have null values for some reason
 		if ( !isset($options[$o]['url']) || !isset($options[$o]['title']) || !isset($options[$o]['items']) )
 			continue;
Index: wp-db.php
===================================================================
--- wp-db.php	(revision 8483)
+++ wp-db.php	(working copy)
@@ -378,7 +378,7 @@
 		$old_prefix = $this->prefix;
 		$this->prefix = $prefix;
 
-		foreach ( $this->tables as $table )
+		foreach ( (array) $this->tables as $table )
 			$this->$table = $this->prefix . $table;
 
 		if ( defined('CUSTOM_USER_TABLE') )
@@ -677,7 +677,7 @@
 	function update($table, $data, $where){
 		$data = add_magic_quotes($data);
 		$bits = $wheres = array();
-		foreach ( array_keys($data) as $k )
+		foreach ( (array) array_keys($data) as $k )
 			$bits[] = "`$k` = '$data[$k]'";
 
 		if ( is_array( $where ) )
@@ -805,7 +805,7 @@
 			// Return an integer-keyed array of...
 			if ( $this->last_result ) {
 				$i = 0;
-				foreach( $this->last_result as $row ) {
+				foreach( (array) $this->last_result as $row ) {
 					if ( $output == ARRAY_N ) {
 						// ...integer-keyed row arrays
 						$new_array[$i] = array_values( get_object_vars( $row ) );
@@ -833,7 +833,7 @@
 		if ( $this->col_info ) {
 			if ( $col_offset == -1 ) {
 				$i = 0;
-				foreach($this->col_info as $col ) {
+				foreach( (array) $this->col_info as $col ) {
 					$new_array[$i] = $col->{$info_type};
 					$i++;
 				}
@@ -941,7 +941,7 @@
 		$bt = debug_backtrace();
 		$caller = '';
 
-		foreach ( $bt as $trace ) {
+		foreach ( (array) $bt as $trace ) {
 			if ( @$trace['class'] == __CLASS__ )
 				continue;
 			elseif ( strtolower(@$trace['function']) == 'call_user_func_array' )
