Skip to content

Commit edead86

Browse files
Merge pull request #73 from wp-cli/fix-undefined-mb
Check that `mb_detect_encoding()` exists too before using
2 parents 98db678 + 1e7b3e2 commit edead86

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/cli/cli.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ function menu( $items, $default = null, $title = 'Choose an item' ) {
160160
* @return int Numeric value that represents the string's length
161161
*/
162162
function safe_strlen( $str ) {
163-
if ( function_exists( 'mb_strlen' ) ) {
163+
if ( function_exists( 'mb_strlen' ) && function_exists( 'mb_detect_encoding' ) ) {
164164
$length = mb_strlen( $str, mb_detect_encoding( $str ) );
165165
} else {
166166
// iconv will return PHP notice if non-ascii characters are present in input string
@@ -182,7 +182,7 @@ function safe_strlen( $str ) {
182182
* @return string Substring of string specified by start and length parameters
183183
*/
184184
function safe_substr( $str, $start, $length = false ) {
185-
if ( function_exists( 'mb_substr' ) ) {
185+
if ( function_exists( 'mb_substr' ) && function_exists( 'mb_detect_encoding' ) ) {
186186
$substr = mb_substr( $str, $start, $length, mb_detect_encoding( $str ) );
187187
} else {
188188
// iconv will return PHP notice if non-ascii characters are present in input string
@@ -204,7 +204,7 @@ function safe_substr( $str, $start, $length = false ) {
204204
function safe_str_pad( $string, $length ) {
205205
// Hebrew vowel characters
206206
$cleaned_string = preg_replace( '#[\x{591}-\x{5C7}]+#u', '', Colors::decolorize( $string ) );
207-
if ( function_exists( 'mb_strwidth' ) ) {
207+
if ( function_exists( 'mb_strwidth' ) && function_exists( 'mb_detect_encoding' ) ) {
208208
$real_length = mb_strwidth( $cleaned_string, mb_detect_encoding( $string ) );
209209
} else {
210210
$real_length = safe_strlen( $cleaned_string );

0 commit comments

Comments
 (0)