|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76708 mb_detect_encoding behaves inconsistenly depending on the argument type
Submitted: 2018-08-05 05:51 UTC Modified: 2018-08-05 06:21 UTC
From: smokey101stair at gmail dot com Assigned:
Status: Duplicate Package: mbstring related
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
44 + 26 = ?
Subscribe to this entry?

 [2018-08-05 05:51 UTC] smokey101stair at gmail dot com
Similar to Bug 76704. mb_detect_encoding()'s second parameter, $encoding_list, takes either an array of encodings or a comma separated string of encodings. However, its behavior varies depending on whether an array or string is passed to $encoding_list, when that value contains both a supported and unsupported encoding.

Test script:

Expected result:
Honestly.. I'm not entirely sure.

Setting mb_detect_encodings()'s second parameter is really doing the same thing as if you had passed the same thing to mb_detect_order(), which returns false (now that Bug 76704 is fixed) if any of the given encodings are not supported. 

Option 1) In the interest of consistency, this should probably also return false if any of the given encodings are not supported. Doing this would probably be a a BC break, and I don't know how popular this function really is.

Option 2) Match what is currently done when an array is given and emit a warning and silently fallback to the value of mb_detect_order().

Option 3) Match what is currently done when a string is given and silently try to match against any of the supported encodings.

Actual result:
If $encoding_list is a string, and tries to match the given string against the supported encoding. No warning is emitted.

If $encoding_list is an array, then a warning is emitted and it tries to match the given string against the fallback value of mb_detect_order().


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-05 06:10 UTC]
-Status: Open +Status: Duplicate
 [2018-08-05 06:10 UTC]
Same cause as the other bug so this got fixed too.
 [2018-08-05 06:17 UTC]
Oh. To be clear, the new behavior has the function issue a warning and use the mb_detect_order value. So option 2.
 [2018-08-05 06:21 UTC] smokey101stair at gmail dot com
Thanks for the explanation.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Oct 04 14:01:25 2023 UTC