Skip to content

Commit 2046b3c

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2: Fix #78609: mb_check_encoding() no longer supports stringable objects
2 parents e546d72 + 45db6fa commit 2046b3c

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
@@ -17,6 +17,8 @@ PHP NEWS
1717
- MBString:
1818
. Fixed bug #78579 (mb_decode_numericentity: args number inconsistency).
1919
(cmb)
20+
. Fixed bug #78609 (mb_check_encoding() no longer supports stringable
21+
objects). (cmb)
2022

2123
- Mysqlnd:
2224
. Fixed bug #78525 (Memory leak in pdo when reusing native prepared

ext/mbstring/mbstring.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4823,27 +4823,15 @@ PHP_FUNCTION(mb_check_encoding)
48234823
RETURN_FALSE;
48244824
}
48254825

4826-
switch(Z_TYPE_P(input)) {
4827-
case IS_LONG:
4828-
case IS_DOUBLE:
4829-
case IS_NULL:
4830-
case IS_TRUE:
4831-
case IS_FALSE:
4832-
RETURN_TRUE;
4833-
break;
4834-
case IS_STRING:
4835-
if (!php_mb_check_encoding(Z_STRVAL_P(input), Z_STRLEN_P(input), enc ? ZSTR_VAL(enc): NULL)) {
4836-
RETURN_FALSE;
4837-
}
4838-
break;
4839-
case IS_ARRAY:
4840-
if (!php_mb_check_encoding_recursive(HASH_OF(input), enc)) {
4841-
RETURN_FALSE;
4842-
}
4843-
break;
4844-
default:
4845-
php_error_docref(NULL, E_WARNING, "Input is something other than scalar or array");
4826+
if (Z_TYPE_P(input) == IS_ARRAY) {
4827+
if (!php_mb_check_encoding_recursive(HASH_OF(input), enc)) {
48464828
RETURN_FALSE;
4829+
}
4830+
} else {
4831+
convert_to_string(input);
4832+
if (!php_mb_check_encoding(Z_STRVAL_P(input), Z_STRLEN_P(input), enc ? ZSTR_VAL(enc): NULL)) {
4833+
RETURN_FALSE;
4834+
}
48474835
}
48484836
RETURN_TRUE;
48494837
}

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)