Code Modernization: Return an empty string from wpdb::_real_escape() if a non-scalar value is passed.

This avoids a fatal error on PHP 8 caused by passing a non-string value to ` mysqli_real_escape_string()`, and maintains the current behaviour.

See #50913, #50639.

git-svn-id: https://develop.svn.wordpress.org/trunk@48980 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2020-09-16 01:46:25 +00:00
parent aadc1d70f2
commit 35ceac68f4

View File

@ -1159,6 +1159,10 @@ class wpdb {
* @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 );