Bug #71188 [Opn->Csd]: str_replace converts integers in original $search array to strings

From: Date: Tue, 22 Dec 2015 03:08:04 +0000
Subject: Bug #71188 [Opn->Csd]: str_replace converts integers in original $search array to strings
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198114@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71188&edit=1 ID: 71188 Updated by: laruence@php.net Reported by: admin at supermartas dot cz Summary: str_replace converts integers in original $search array to strings -Status: Open +Status: Closed Type: Bug Package: Strings related Operating System: Any PHP Version: 7.0.1 Block user comment: N Private report: N New Comment: Automatic comment on behalf of laruence@gmail.com Revision: http://git.php.net/?p=php-src.git;a=commit;h=3524849f77c1bd7fa582b256b891171c8ca4f830 Log: Fixed #71188 (str_replace converts integers in original $search array to strings) Previous Comments: ------------------------------------------------------------------------ [2015-12-21 23:31:25] admin at supermartas dot cz Description: ------------ If I try the test script on Windows 10 or (probably) on CentOS, I will get this result: array(3) { [0]=> int(0) [1]=> int(1) [2]=> int(2) } array(3) { [0]=> string(1) "0" [1]=> string(1) "1" [2]=> string(1) "2" } PHP converted all integers in $a array to strings but the original array should stay untouched! But it's even worse on Ubuntu 14.04.3 LTS (PHP Version 7.0.1-2+deb.sury.org~trusty+1) where it returns at first the same result as on the other operating systems but after some page refreshes (press F5 in your browser about 20 times) it returns: array(3) { [0]=> string(1) "0" [1]=> string(875835694) "<br /> <b>Fatal error</b>: Allowed memory size of 134217728 bytes exhausted (tried to allocate 3688507696953442304 bytes) or sometimes: array(3) { [0]=> string(1862275224) "<br /> <b>Fatal error</b>: Allowed memory size of 134217728 bytes exhausted (tried to allocate 140065040769024 bytes) In another script (where I found out there is something wrong with PHP) it didn't throw that fatal error but it modified the $a array like this (original $a array has 10 items): array(10) { [0]=> string(5) "https" [1]=> string(5) "https" [2]=> string(0) "" [3]=> string(5) "15421" [4]=> string(5) "15421" [5]=> string(7) "CGI/1.1" [6]=> string(6) "HTTP/2" [7]=> string(6) "HTTP/2" [8]=> string(5) "close" [9]=> string(1) "0" } If I convert items of $a array to string by hand ($a = ["0", "1", "2"]), everything is working correctly. Test script: --------------- <?php $a = [0, 1, 2]; $b = ["Nula", "Jedna", "Dva"]; var_dump($a); str_replace($a, $b, "1"); var_dump($a); Expected result: ---------------- array(3) { [0]=> int(0) [1]=> int(1) [2]=> int(2) } array(3) { [0]=> int(0) [1]=> int(1) [2]=> int(2) } Actual result: -------------- array(3) { [0]=> int(0) [1]=> int(1) [2]=> int(2) } array(3) { [0]=> string(1) "0" [1]=> string(1) "1" [2]=> string(1) "2" } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71188&edit=1

« previous php.bugs (#198114) next »