diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php
index bc673191a8..a6ded6cf1e 100644
--- a/src/wp-includes/class-wp-query.php
+++ b/src/wp-includes/class-wp-query.php
@@ -1015,7 +1015,7 @@ class WP_Query {
 			$this->is_admin = true;
 		}
 
-		if ( str_contains( $qv['feed'], 'comments-' ) ) {
+		if ( is_string( $qv['feed'] ) && str_contains( $qv['feed'], 'comments-' ) ) {
 			$qv['feed']         = str_replace( 'comments-', '', $qv['feed'] );
 			$qv['withcomments'] = 1;
 		}
diff --git a/src/wp-includes/class-wp.php b/src/wp-includes/class-wp.php
index ce88c102cf..c5b2dbb66b 100644
--- a/src/wp-includes/class-wp.php
+++ b/src/wp-includes/class-wp.php
@@ -469,6 +469,12 @@ class WP {
 		} else {
 			// Set the correct content type for feeds.
 			$type = $this->query_vars['feed'];
+
+			// Ensure $type is a string
+			if ( ! is_string( $type ) ) {
+				$type = get_default_feed();
+			}
+
 			if ( 'feed' === $this->query_vars['feed'] ) {
 				$type = get_default_feed();
 			}
@@ -477,7 +483,7 @@ class WP {
 
 			// We're showing a feed, so WP is indeed the only thing that last changed.
 			if ( ! empty( $this->query_vars['withcomments'] )
-				|| str_contains( $this->query_vars['feed'], 'comments-' )
+				|| ( is_string( $this->query_vars['feed'] ) && str_contains( $this->query_vars['feed'], 'comments-' ) )
 				|| ( empty( $this->query_vars['withoutcomments'] )
 					&& ( ! empty( $this->query_vars['p'] )
 						|| ! empty( $this->query_vars['name'] )
