Skip to content

Commit 70f367d

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #78609: mb_check_encoding() no longer supports stringable objects
2 parents 27f5785 + 2046b3c commit 70f367d

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ PHP NEWS
1515
- MBString:
1616
. Fixed bug #78579 (mb_decode_numericentity: args number inconsistency).
1717
(cmb)
18+
. Fixed bug #78609 (mb_check_encoding() no longer supports stringable
19+
objects). (cmb)
1820

1921
- Standard:
2022
. Fixed bug #78549 (Stack overflow due to nested serialized input). (Nikita)

ext/mbstring/mbstring.c

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4952,27 +4952,17 @@ PHP_FUNCTION(mb_check_encoding)
49524952
RETURN_FALSE;
49534953
}
49544954

4955-
switch(Z_TYPE_P(input)) {
4956-
case IS_LONG:
4957-
case IS_DOUBLE:
4958-
case IS_NULL:
4959-
case IS_TRUE:
4960-
case IS_FALSE:
4961-
RETURN_TRUE;
4962-
break;
4963-
case IS_STRING:
4964-
if (!php_mb_check_encoding(Z_STRVAL_P(input), Z_STRLEN_P(input), enc ? ZSTR_VAL(enc): NULL)) {
4965-
RETURN_FALSE;
4966-
}
4967-
break;
4968-
case IS_ARRAY:
4969-
if (!php_mb_check_encoding_recursive(Z_ARRVAL_P(input), enc)) {
4970-
RETURN_FALSE;
4971-
}
4972-
break;
4973-
default:
4974-
php_error_docref(NULL, E_WARNING, "Input is something other than scalar or array");
4955+
if (Z_TYPE_P(input) == IS_ARRAY) {
4956+
if (!php_mb_check_encoding_recursive(HASH_OF(input), enc)) {
4957+
RETURN_FALSE;
4958+
}
4959+
} else {
4960+
if (!try_convert_to_string(input)) {
4961+
RETURN_FALSE;
4962+
}
4963+
if (!php_mb_check_encoding(Z_STRVAL_P(input), Z_STRLEN_P(input), enc ? ZSTR_VAL(enc): NULL)) {
49754964
RETURN_FALSE;
4965+
}
49764966
}
49774967
RETURN_TRUE;
49784968
}

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)