Index: src/wp-includes/class-wp-query.php
===================================================================
--- src/wp-includes/class-wp-query.php	(revision 43005)
+++ src/wp-includes/class-wp-query.php	(working copy)
@@ -1161,7 +1161,7 @@
 			if ( ! isset( $q['category__in'] ) ) {
 				$q['category__in'] = array();
 			}
-			$q['category__in'][] = absint( reset( $q['category__and'] ) );
+			$q['category__in'][] = absint( $this->reset( $q['category__and'] ) );
 			unset( $q['category__and'] );
 		}
 
@@ -1504,7 +1504,7 @@
 			}
 		} else {
 			// single word or sentence search
-			$search_orderby = reset( $q['search_orderby_title'] ) . ' DESC';
+			$search_orderby = $this->reset( $q['search_orderby_title'] ) . ' DESC';
 		}
 
 		return $search_orderby;
@@ -1549,7 +1549,7 @@
 		$primary_meta_query = false;
 		$meta_clauses       = $this->meta_query->get_clauses();
 		if ( ! empty( $meta_clauses ) ) {
-			$primary_meta_query = reset( $meta_clauses );
+			$primary_meta_query = $this->reset( $meta_clauses );
 
 			if ( ! empty( $primary_meta_query['key'] ) ) {
 				$primary_meta_key = $primary_meta_query['key'];
@@ -2319,7 +2319,7 @@
 			$post_type_cap = 'multiple_post_type';
 		} else {
 			if ( is_array( $post_type ) ) {
-				$post_type = reset( $post_type );
+				$post_type = $this->reset( $post_type );
 			}
 			$post_type_object = get_post_type_object( $post_type );
 			if ( empty( $post_type_object ) ) {
@@ -3119,7 +3119,7 @@
 				update_post_caches( $this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
 			}
 
-			$this->post = reset( $this->posts );
+			$this->post = $this->reset( $this->posts );
 		} else {
 			$this->post_count = 0;
 			$this->posts      = array();
@@ -3396,14 +3396,14 @@
 				// For other tax queries, grab the first term from the first clause.
 				if ( ! empty( $this->tax_query->queried_terms ) ) {
 					$queried_taxonomies = array_keys( $this->tax_query->queried_terms );
-					$matched_taxonomy   = reset( $queried_taxonomies );
+					$matched_taxonomy   = $this->reset( $queried_taxonomies );
 					$query              = $this->tax_query->queried_terms[ $matched_taxonomy ];
 
 					if ( ! empty( $query['terms'] ) ) {
 						if ( 'term_id' == $query['field'] ) {
-							$term = get_term( reset( $query['terms'] ), $matched_taxonomy );
+							$term = get_term( $this->reset( $query['terms'] ), $matched_taxonomy );
 						} else {
-							$term = get_term_by( $query['field'], reset( $query['terms'] ), $matched_taxonomy );
+							$term = get_term_by( $query['field'], $this->reset( $query['terms'] ), $matched_taxonomy );
 						}
 					}
 				}
@@ -3420,7 +3420,7 @@
 		} elseif ( $this->is_post_type_archive ) {
 			$post_type = $this->get( 'post_type' );
 			if ( is_array( $post_type ) ) {
-				$post_type = reset( $post_type );
+				$post_type = $this->reset( $post_type );
 			}
 			$this->queried_object = get_post_type_object( $post_type );
 		} elseif ( $this->is_posts_page ) {
@@ -3542,7 +3542,7 @@
 
 		$post_type = $this->get( 'post_type' );
 		if ( is_array( $post_type ) ) {
-			$post_type = reset( $post_type );
+			$post_type = $this->reset( $post_type );
 		}
 		$post_type_object = get_post_type_object( $post_type );
 
@@ -4250,4 +4250,22 @@
 		_deprecated_function( __METHOD__, '4.5.0' );
 		return $check;
 	}
+
+	/**
+	 * Returns the first element of an array.
+	 * This is introduced as a replacement
+	 * of the PHP native function reset()
+	 * for performance improvement.
+	 *
+	 * @since 5.0.0
+	 *
+	 * @param array $array
+	 *
+	 * @return mixed
+	 */
+	private function reset( $array ) {
+		foreach ( $array as $element ) {
+			return $element;
+		}
+	}
 }
