php.net |  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
Description:
------------
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);
var_dump($x);


Expected result:
----------------
array(1) {
  ["a"]=>
  int(1)
}

Actual result:
--------------
array(1) {
  ["a"]=>
  string(1) "1"
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-24 11:59 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2017-10-24 11:59 UTC] requinix@php.net
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] nikic@php.net
I can't reproduce this behavior with the provided test script: https://3v4l.org/fZH3m
 [2017-10-24 12:20 UTC] requinix@php.net
...huh.
https://github.com/php/php-src/blob/PHP-7.1.10/ext/mbstring/mbstring.c#L3881
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: Fri Dec 06 07:01:29 2024 UTC