Skip to content

Commit 45db6fa

Browse files
committed
Fix #78609: mb_check_encoding() no longer supports stringable objects
We apply type juggling for other types than array.
1 parent f6bfbe9 commit 45db6fa

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ PHP NEWS
1313
- MBString:
1414
. Fixed bug #78579 (mb_decode_numericentity: args number inconsistency).
1515
(cmb)
16+
. Fixed bug #78609 (mb_check_encoding() no longer supports stringable
17+
objects). (cmb)
1618

1719
- Standard:
1820
. Fixed bug #76342 (file_get_contents waits twice specified timeout).

ext/mbstring/mbstring.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5027,27 +5027,15 @@ PHP_FUNCTION(mb_check_encoding)
50275027
RETURN_FALSE;
50285028
}
50295029

5030-
switch(Z_TYPE_P(input)) {
5031-
case IS_LONG:
5032-
case IS_DOUBLE:
5033-
case IS_NULL:
5034-
case IS_TRUE:
5035-
case IS_FALSE:
5036-
RETURN_TRUE;
5037-
break;
5038-
case IS_STRING:
5039-
if (!php_mb_check_encoding(Z_STRVAL_P(input), Z_STRLEN_P(input), enc ? ZSTR_VAL(enc): NULL)) {
5040-
RETURN_FALSE;
5041-
}
5042-
break;
5043-
case IS_ARRAY:
5044-
if (!php_mb_check_encoding_recursive(HASH_OF(input), enc)) {
5045-
RETURN_FALSE;
5046-
}
5047-
break;
5048-
default:
5049-
php_error_docref(NULL, E_WARNING, "Input is something other than scalar or array");
5030+
if (Z_TYPE_P(input) == IS_ARRAY) {
5031+
if (!php_mb_check_encoding_recursive(HASH_OF(input), enc)) {
50505032
RETURN_FALSE;
5033+
}
5034+
} else {
5035+
convert_to_string(input);
5036+
if (!php_mb_check_encoding(Z_STRVAL_P(input), Z_STRLEN_P(input), enc ? ZSTR_VAL(enc): NULL)) {
5037+
RETURN_FALSE;
5038+
}
50515039
}
50525040
RETURN_TRUE;
50535041
}

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)