php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81011 mb_convert_encoding removes references from arrays
Submitted: 2021-05-04 13:04 UTC Modified: 2021-05-04 16:44 UTC
From: mvalihora at gmail dot com Assigned: cmb (profile)
Status: Closed Package: mbstring related
PHP Version: 7.4.18 OS: All
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:
MUST BE VALID
Solve the problem:
50 - 35 = ?
Subscribe to this entry?

 
 [2021-05-04 13:04 UTC] mvalihora at gmail dot com
Description:
------------
when some elements in array are changed by reference and this array is then converted using mb_convert_encoding, these elements are removed or empty. Warning is emmited "mb_convert_encoding(): Object is not supported in ...", but function returns result without mentioned elements. Best see in code example.

Test script:
---------------
// any sample array, structure does not matter
$array = [
    'ads' => [
        123 => ['name' => 'this', 'id' => 444],
        234 => ['name' => 'that', 'id' => 555],
    ],
    'other' => ['one', 'two']
    ];
         
// we modify array elements using reference     
foreach( $array['ads'] as &$ad ){
    $ad['premium'] = (int)($ad['id'] == 555);
}

// print_r prints array contents OK
print_r($array);

// mb_convert_encoding emits Warning, but returns result where modified array elements are removed - in this case 'ads' element

print_r(mb_convert_encoding($array, 'UTF-8', 'UTF-8'));

Expected result:
----------------
array elements does not disappear, mb_convert_encoding does not emit warning

Actual result:
--------------
mb_convert_encoding returns result where modified array elements are removed. mb_convert_encoding emits warning

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-05-04 13:34 UTC] cmb@php.net
-Summary: mb_convert_encoding removes array alements +Summary: mb_convert_encoding removes references from arrays -Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2021-05-04 13:44 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #81011: mb_convert_encoding removes references from arrays
On GitHub:  https://github.com/php/php-src/pull/6938
Patch:      https://github.com/php/php-src/pull/6938.patch
 [2021-05-04 16:44 UTC] cmb@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 23:01:26 2024 UTC