wp/wp-includes/wp-db.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
--- a/wp/wp-includes/wp-db.php	Tue Dec 15 15:52:01 2020 +0100
+++ b/wp/wp-includes/wp-db.php	Wed Sep 21 18:19:35 2022 +0200
@@ -61,7 +61,7 @@
 	 * @since 0.71
 	 * @var bool
 	 */
-	var $show_errors = false;
+	public $show_errors = false;
 
 	/**
 	 * Whether to suppress errors during the DB bootstrapping. Default false.
@@ -69,7 +69,7 @@
 	 * @since 2.5.0
 	 * @var bool
 	 */
-	var $suppress_errors = false;
+	public $suppress_errors = false;
 
 	/**
 	 * The error encountered during the last query.
@@ -101,7 +101,7 @@
 	 * @since 0.71
 	 * @var int
 	 */
-	var $rows_affected = 0;
+	public $rows_affected = 0;
 
 	/**
 	 * The ID generated for an AUTO_INCREMENT column by the last query (usually INSERT).
@@ -117,7 +117,7 @@
 	 * @since 0.71
 	 * @var string
 	 */
-	var $last_query;
+	public $last_query;
 
 	/**
 	 * Results of the last query.
@@ -125,7 +125,7 @@
 	 * @since 0.71
 	 * @var array|null
 	 */
-	var $last_result;
+	public $last_result;
 
 	/**
 	 * MySQL result, which is either a resource or boolean.
@@ -198,7 +198,7 @@
 	 *     }
 	 * }
 	 */
-	var $queries;
+	public $queries;
 
 	/**
 	 * The number of times to retry reconnecting before dying. Default 5.
@@ -234,7 +234,7 @@
 	 * @since 2.3.2
 	 * @var bool
 	 */
-	var $ready = false;
+	public $ready = false;
 
 	/**
 	 * Blog ID.
@@ -259,7 +259,7 @@
 	 * @see wpdb::tables()
 	 * @var array
 	 */
-	var $tables = array(
+	public $tables = array(
 		'posts',
 		'comments',
 		'links',
@@ -281,7 +281,7 @@
 	 * @see wpdb::tables()
 	 * @var array
 	 */
-	var $old_tables = array( 'categories', 'post2cat', 'link2cat' );
+	public $old_tables = array( 'categories', 'post2cat', 'link2cat' );
 
 	/**
 	 * List of WordPress global tables.
@@ -290,7 +290,7 @@
 	 * @see wpdb::tables()
 	 * @var array
 	 */
-	var $global_tables = array( 'users', 'usermeta' );
+	public $global_tables = array( 'users', 'usermeta' );
 
 	/**
 	 * List of Multisite global tables.
@@ -299,7 +299,7 @@
 	 * @see wpdb::tables()
 	 * @var array
 	 */
-	var $ms_global_tables = array(
+	public $ms_global_tables = array(
 		'blogs',
 		'blogmeta',
 		'signups',
@@ -1159,6 +1159,10 @@
 	 * @return string Escaped string.
 	 */
 	function _real_escape( $string ) {
+		if ( ! is_scalar( $string ) && ! is_null( $string ) ) {
+			return '';
+		}
+
 		if ( $this->dbh ) {
 			if ( $this->use_mysqli ) {
 				$escaped = mysqli_real_escape_string( $this->dbh, $string );
@@ -1365,7 +1369,9 @@
 		// Count the number of valid placeholders in the query.
 		$placeholders = preg_match_all( "/(^|[^%]|(%%)+)%($allowed_format)?[sdF]/", $query, $matches );
 
-		if ( count( $args ) !== $placeholders ) {
+		$args_count = count( $args );
+
+		if ( $args_count !== $placeholders ) {
 			if ( 1 === $placeholders && $passed_as_array ) {
 				// If the passed query only expected one argument, but the wrong number of arguments were sent as an array, bail.
 				wp_load_translations_early();
@@ -1388,10 +1394,22 @@
 						/* translators: 1: Number of placeholders, 2: Number of arguments passed. */
 						__( 'The query does not contain the correct number of placeholders (%1$d) for the number of arguments passed (%2$d).' ),
 						$placeholders,
-						count( $args )
+						$args_count
 					),
 					'4.8.3'
 				);
+
+				/*
+				 * If we don't have enough arguments to match the placeholders,
+				 * return an empty string to avoid a fatal error on PHP 8.
+				 */
+				if ( $args_count < $placeholders ) {
+					$max_numbered_placeholder = ! empty( $matches[3] ) ? max( array_map( 'intval', $matches[3] ) ) : 0;
+
+					if ( ! $max_numbered_placeholder || $args_count < $max_numbered_placeholder ) {
+						return '';
+					}
+				}
 			}
 		}
 
@@ -1869,11 +1887,11 @@
 	/**
 	 * Performs a MySQL database query, using current database connection.
 	 *
-	 * More information can be found on the Codex page.
+	 * More information can be found on the documentation page.
 	 *
 	 * @since 0.71
 	 *
-	 * @link https://codex.wordpress.org/Function_Reference/wpdb_Class
+	 * @link https://developer.wordpress.org/reference/classes/wpdb/
 	 *
 	 * @param string $query Database query.
 	 * @return int|bool Boolean true for CREATE, ALTER, TRUNCATE and DROP queries. Number of rows
@@ -1897,6 +1915,11 @@
 		 */
 		$query = apply_filters( 'query', $query );
 
+		if ( ! $query ) {
+			$this->insert_id = 0;
+			return false;
+		}
+
 		$this->flush();
 
 		// Log how the function was called.
@@ -2060,11 +2083,10 @@
 	 */
 	public function log_query( $query, $query_time, $query_callstack, $query_start, $query_data ) {
 		/**
-		 * Filters the custom query data being logged.
+		 * Filters the custom data to log alongside a query.
 		 *
 		 * Caution should be used when modifying any of this data, it is recommended that any additional
-		 * information you need to store about a query be added as a new associative entry to the fourth
-		 * element $query_data.
+		 * information you need to store about a query be added as a new associative array element.
 		 *
 		 * @since 5.3.0
 		 *
@@ -3623,10 +3645,7 @@
 	}
 
 	/**
-	 * Retrieves the name of the function that called wpdb.
-	 *
-	 * Searches up the list of functions until it reaches the one that would
-	 * most logically had called this method.
+	 * Retrieves a comma-separated list of the names of the functions that called wpdb.
 	 *
 	 * @since 2.5.0
 	 *