Bug #81312 [Opn]: mb_convert_variables() corrupts reference of array element

From: Date: Mon, 02 Aug 2021 14:33:19 +0000
Subject: Bug #81312 [Opn]: mb_convert_variables() corrupts reference of array element
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235530@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81312&edit=1 ID: 81312 Updated by: nikic@php.net Reported by: heguangyu5 at qq dot com Summary: mb_convert_variables() corrupts reference of array element Status: Open Type: Bug Package: mbstring related Operating System: ubuntu PHP Version: 7.4.22 Block user comment: N Private report: N New Comment: The current behavior is tested in https://github.com/php/php-src/blob/master/ext/mbstring/tests/bug26639.phpt. Though the original bug report (https://bugs.php.net/bug.php?id=26639) doesn't talk about references, but only missing copy-on-write. I'm includes to agree that the current behavior is incorrect. Previous Comments: ------------------------------------------------------------------------ [2021-07-30 03:18:38] heguangyu5 at qq dot com Description: ------------ mb_convert_variables() should only convert enconding of array elements but not change the array structure. Test script: --------------- <?php $a = "‚ ‚¢‚€‚Š‚š"; $b = array(&$a); $c = $b; var_dump($a, $b, $c); $c[0] .= " abc"; var_dump($a, $b, $c); mb_convert_variables("EUC-JP", "Shift_JIS", $c); var_dump($a, $b, $c); $c[0] .= " def"; var_dump($a, $b, $c); Expected result: ---------------- string(10) "‚ ‚¢‚€‚Š‚š" array(1) { [0]=> &string(10) "‚ ‚¢‚€‚Š‚š" } array(1) { [0]=> &string(10) "‚ ‚¢‚€‚Š‚š" } string(15) "‚ ‚¢‚€‚Š‚š abc" array(1) { [0]=> &string(15) "‚ ‚¢‚€‚Š‚š abc" } array(1) { [0]=> &string(15) "‚ ‚¢‚€‚Š‚š abc" } string(15) "€¢€€€Š€š€ª abc" array(1) { [0]=> &string(15) "€¢€€€Š€š€ª abc" } array(1) { [0]=> &string(15) "€¢€€€Š€š€ª abc" } string(20) "€¢€€€Š€š€ª abc def" array(1) { [0]=> &string(20) "€¢€€€Š€š€ª abc def" } array(1) { [0]=> &string(20) "€¢€€€Š€š€ª abc def" } Actual result: -------------- string(10) "‚ ‚¢‚€‚Š‚š" array(1) { [0]=> &string(10) "‚ ‚¢‚€‚Š‚š" } array(1) { [0]=> &string(10) "‚ ‚¢‚€‚Š‚š" } string(15) "‚ ‚¢‚€‚Š‚š abc" array(1) { [0]=> &string(15) "‚ ‚¢‚€‚Š‚š abc" } array(1) { [0]=> &string(15) "‚ ‚¢‚€‚Š‚š abc" } string(15) "‚ ‚¢‚€‚Š‚š abc" array(1) { [0]=> &string(15) "‚ ‚¢‚€‚Š‚š abc" } array(1) { [0]=> string(15) "€¢€€€Š€š€ª abc" } string(15) "‚ ‚¢‚€‚Š‚š abc" array(1) { [0]=> &string(15) "‚ ‚¢‚€‚Š‚š abc" } array(1) { [0]=> string(20) "€¢€€€Š€š€ª abc def" } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=81312&edit=1

« previous php.bugs (#235530) next »