From d345fe2e696ed59d676b92b4eec7aa34e57ad58d Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Fri, 10 Sep 2021 16:36:57 +0000 Subject: [PATCH] Code Modernization: Fix "passing null to non-nullable" deprecation in `wpdb::_real_escape()`. The PHP native `mysqli_real_escape_string()` function expects to be passed a string as the second parameter and this is not a nullable parameter. Passing `null` to it will result in a `mysqli_real_escape_string(): Passing null to parameter #2 ($string) of type string is deprecated` notice on PHP 8.1. Previously, an input type check was put in place to prevent fatal errors on PHP 8.0 when an array, object or resource was passed. Changeset [48980]. A `null` value was explicitly excluded from that check, even though a `null` value being passed would only ever result in an empty string anyway. This commit changes the previous input type check to also bow out early for `null` values and to automatically return an empty string for those. Refs: - https://www.php.net/manual/en/mysqli.real-escape-string.php - https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg Follow-up to [48980]. Props jrf, hellofromTonya. See #53635. Built from https://develop.svn.wordpress.org/trunk@51799 git-svn-id: http://core.svn.wordpress.org/trunk@51406 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/version.php | 2 +- wp-includes/wp-db.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wp-includes/version.php b/wp-includes/version.php index af7270325a..85ee689f5e 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-51798'; +$wp_version = '5.9-alpha-51799'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php index 04fa15c1ee..340a6f5861 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -1158,7 +1158,7 @@ class wpdb { * @return string Escaped string. */ function _real_escape( $string ) { - if ( ! is_scalar( $string ) && ! is_null( $string ) ) { + if ( ! is_scalar( $string ) ) { return ''; }