#33773 [Opn->Csd]: str_replace recursion

From: Date: Tue, 19 Jul 2005 18:04:35 +0000
Subject: #33773 [Opn->Csd]: str_replace recursion
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-82158@lists.php.net to get a copy of this message
ID: 33773 User updated by: tomlove at gmail dot com -Summary: str_replace - recursive replace for arrays is dangerous Reported By: tomlove at gmail dot com -Status: Open +Status: Closed Bug Type: Feature/Change Request Operating System: Linux / Windows PHP Version: 4.3.11 New Comment: Actually, I realise it wouldn't be a trivial to change this behaviour. Probably better to leave checks for recursive cases to the script. Previous Comments: ------------------------------------------------------------------------ [2005-07-19 18:14:12] tomlove at gmail dot com Description: ------------ I assume this is a feature: str_replace recursively replaces when both $search and $replace are arrays. It's too easy for this to cause runaway memory consumption though. I've never needed to take advantage of the recursive nature of the function, and wouldn't expect many others to. The code below is enough to hang my system. Reproduce code: --------------- for ($i = 0; $i < 50; $i++) { $arr1[$i] = "foo"; $arr2[$i] = "foobarfoo"; } $str = "foobar"; echo str_replace($arr1, $arr2, $str); Expected result: ---------------- Ideally: foobarfoobar Actual result: -------------- foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar.... ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=33773&edit=1

« previous php.bugs (#82158) next »