|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75425 mb_convert_variables converts integers to strings
Submitted: 2017-10-24 11:42 UTC Modified: 2017-10-24 12:44 UTC
From: info at its-mieger dot de Assigned:
Status: Closed Package: mbstring related
PHP Version: 7.1.10 OS: debian
Private report: No CVE-ID: None
 [2017-10-24 11:42 UTC] info at its-mieger dot de
Integer values are converted to strings by mb_convert_variables. But variable types should be kept

Test script:
$x = ["a" => 1];
mb_convert_variables("UTF-8", "ISO-8859-15", $x);

Expected result:
array(1) {

Actual result:
array(1) {
  string(1) "1"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-24 11:59 UTC]
-Status: Open +Status: Feedback
 [2017-10-24 11:59 UTC]
Well yeah: it's as if you wrote
  $x["a"] = mb_convert_encoding($x["a"], "UTF-8", "ISO-8859-15");

I would expect mb_convert_variables() to work on strings (or recursively on arrays and objects) and not to silently pass through values of a non-conforming type. It's like how
  substr("123", 0, 1)
is the string "1" and not the integer 1 (let alone 123). Type casting like that is standard behavior for PHP.

Does that make sense?
 [2017-10-24 12:01 UTC]
I can't reproduce this behavior with the provided test script:
 [2017-10-24 12:20 UTC]
The conversion process clearly only considers arrays, objects, and strings. I really didn't expect that.

@info, can you reproduce with that exact script you gave? Perhaps the values in your real code are coming from $_GET or $_POST?
 [2017-10-24 12:44 UTC] info at its-mieger dot de
-Status: Feedback +Status: Closed
 [2017-10-24 12:44 UTC] info at its-mieger dot de
oh no!

...there was script included which emulated the mb_convert_variables function in case the mbstring extension is not installed.

Did not realize that. Sorry for reporting this as bug.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Mar 02 01:01:28 2024 UTC