From ba505963fb68d78b24a3fb4cce160d4cb0b4ee5d Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 26 May 2021 16:04:50 +0000 Subject: [PATCH] General: Avoid a PHP warning when checking the `mbstring.func_overload` PHP value. This avoids "A non-numeric value encountered" warning when `mbstring.func_overload` is set to something other than a numeric string, e.g. an empty string instead of the default `'0'` value. Props djbu. Fixes #53282. git-svn-id: https://develop.svn.wordpress.org/trunk@51032 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 8 +++++++- src/wp-includes/pomo/streams.php | 11 +++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index fc1dd011e1..6a4d3e5151 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -6862,7 +6862,13 @@ function mbstring_binary_safe_encoding( $reset = false ) { static $overloaded = null; if ( is_null( $overloaded ) ) { - $overloaded = function_exists( 'mb_internal_encoding' ) && ( ini_get( 'mbstring.func_overload' ) & 2 ); // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.mbstring_func_overloadDeprecated + if ( function_exists( 'mb_internal_encoding' ) + && ( (int) ini_get( 'mbstring.func_overload' ) & 2 ) // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.mbstring_func_overloadDeprecated + ) { + $overloaded = true; + } else { + $overloaded = false; + } } if ( false === $overloaded ) { diff --git a/src/wp-includes/pomo/streams.php b/src/wp-includes/pomo/streams.php index 3978d65791..a8a3755681 100644 --- a/src/wp-includes/pomo/streams.php +++ b/src/wp-includes/pomo/streams.php @@ -18,8 +18,15 @@ if ( ! class_exists( 'POMO_Reader', false ) ) : * PHP5 constructor. */ function __construct() { - $this->is_overloaded = ( ( ini_get( 'mbstring.func_overload' ) & 2 ) != 0 ) && function_exists( 'mb_substr' ); // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.mbstring_func_overloadDeprecated - $this->_pos = 0; + if ( function_exists( 'mb_substr' ) + && ( (int) ini_get( 'mbstring.func_overload' ) & 2 ) // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.mbstring_func_overloadDeprecated + ) { + $this->is_overloaded = true; + } else { + $this->is_overloaded = false; + } + + $this->_pos = 0; } /**