Skip to content

Commit d0d7508

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #78609: mb_check_encoding() no longer supports stringable objects
2 parents b442a9b + 70f367d commit d0d7508

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

ext/mbstring/mbstring.c

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4820,27 +4820,17 @@ PHP_FUNCTION(mb_check_encoding)
48204820
RETURN_FALSE;
48214821
}
48224822

4823-
switch(Z_TYPE_P(input)) {
4824-
case IS_LONG:
4825-
case IS_DOUBLE:
4826-
case IS_NULL:
4827-
case IS_TRUE:
4828-
case IS_FALSE:
4829-
RETURN_TRUE;
4830-
break;
4831-
case IS_STRING:
4832-
if (!php_mb_check_encoding(Z_STRVAL_P(input), Z_STRLEN_P(input), enc ? ZSTR_VAL(enc): NULL)) {
4833-
RETURN_FALSE;
4834-
}
4835-
break;
4836-
case IS_ARRAY:
4837-
if (!php_mb_check_encoding_recursive(Z_ARRVAL_P(input), enc)) {
4838-
RETURN_FALSE;
4839-
}
4840-
break;
4841-
default:
4842-
php_error_docref(NULL, E_WARNING, "Input is something other than scalar or array");
4823+
if (Z_TYPE_P(input) == IS_ARRAY) {
4824+
if (!php_mb_check_encoding_recursive(HASH_OF(input), enc)) {
4825+
RETURN_FALSE;
4826+
}
4827+
} else {
4828+
if (!try_convert_to_string(input)) {
4829+
RETURN_FALSE;
4830+
}
4831+
if (!php_mb_check_encoding(Z_STRVAL_P(input), Z_STRLEN_P(input), enc ? ZSTR_VAL(enc): NULL)) {
48434832
RETURN_FALSE;
4833+
}
48444834
}
48454835
RETURN_TRUE;
48464836
}

ext/mbstring/tests/bug78609.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Bug #78609 (mb_check_encoding() no longer supports stringable objects)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('mbstring')) die('skip mbstring extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
class Foo
10+
{
11+
public function __toString()
12+
{
13+
return 'string_representation';
14+
}
15+
}
16+
17+
var_dump(mb_check_encoding(new Foo, 'UTF-8'));
18+
?>
19+
--EXPECT--
20+
bool(true)

0 commit comments

Comments
 (0)