[php-src] Issue #11754: Warning conversion when str_replace receives a array of array in $subject

From: Date: Fri, 21 Jul 2023 00:07:00 +0000
Subject: [php-src] Issue #11754: Warning conversion when str_replace receives a array of array in $subject
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-245003@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/11754 Author: hdfmacedo ### Description The following code: ```php <?php $a = array( "ram" => "12mb of RAM" , "hard_drive" => "500mb HD" , "capabilities" => array("spreadsheet") , "utility" => array("programming", "gaming", "and stuffs", "HD") ); var_dump($a); var_dump(str_replace("HD", "hard drive", $a)); ``` Resulted in this output: ``` array(4) { ["ram"]=> string(11) "12mb of RAM" ["hard_drive"]=> string(8) "500mb HD" ["capabilities"]=> array(1) { [0]=> string(11) "spreadsheet" } ["utility"]=> array(4) { [0]=> string(11) "programming" [1]=> string(6) "gaming" [2]=> string(10) "and stuffs" [3]=> string(2) "HD" } } Warning: Array to string conversion in C:\commbox\web\testes\index.php on line 11 Warning: Array to string conversion in C:\commbox\web\testes\index.php on line 11 array(4) { ["ram"]=> string(11) "12mb of RAM" ["hard_drive"]=> string(16) "500mb hard drive" ["capabilities"]=> string(5) "Array" ["utility"]=> string(5) "Array" } ``` But I expected this output instead: ``` array(4) { ["ram"]=> string(11) "12mb of RAM" ["hard_drive"]=> string(8) "500mb HD" ["capabilities"]=> array(1) { [0]=> string(11) "spreadsheet" } ["utility"]=> array(4) { [0]=> string(11) "programming" [1]=> string(6) "gaming" [2]=> string(10) "and stuffs" [3]=> string(2) "HD" } } array(4) { ["ram"]=> string(11) "12mb of RAM" ["hard_drive"]=> string(16) "500mb hard drive" ["capabilities"]=> array(1) { [0]=> string(11) "spreadsheet" } ["utility"]=> array(4) { [0]=> string(11) "programming" [1]=> string(6) "gaming" [2]=> string(10) "and stuffs" [3]=> string(2) "hard drive" } } ``` PHP 7.4.30 works this way (without replacing the content of the second level array ``` array(4) { ["ram"]=> string(11) "12mb of RAM" ["hard_drive"]=> string(8) "500mb HD" ["capabilities"]=> array(1) { [0]=> string(11) "spreadsheet" } ["utility"]=> array(4) { [0]=> string(11) "programming" [1]=> string(6) "gaming" [2]=> string(10) "and stuffs" [3]=> string(2) "HD" } } array(4) { ["ram"]=> string(11) "12mb of RAM" ["hard_drive"]=> string(16) "500mb hard drive" ["capabilities"]=> array(1) { [0]=> string(11) "spreadsheet" } ["utility"]=> array(4) { [0]=> string(11) "programming" [1]=> string(6) "gaming" [2]=> string(10) "and stuffs" [3]=> string(2) "HD" } } ``` ### PHP Version 8.2.8 ### Operating System Windows 10

« previous php.bugs (#245003) next »