#33773 [NEW]: str_replace - recursive replace for arrays is dangerous

From: Date: Tue, 19 Jul 2005 16:14:12 +0000
Subject: #33773 [NEW]: str_replace - recursive replace for arrays is dangerous
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-82154@lists.php.net to get a copy of this message
From: tomlove at gmail dot com Operating system: Linux / Windows PHP version: 4.3.11 PHP Bug Type: Feature/Change Request Bug description: str_replace - recursive replace for arrays is dangerous 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 bug report at http://bugs.php.net/?id=33773&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33773&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=33773&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=33773&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=33773&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=33773&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=33773&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=33773&r=needscript Try newer version: http://bugs.php.net/fix.php?id=33773&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=33773&r=support Expected behavior: http://bugs.php.net/fix.php?id=33773&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=33773&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=33773&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=33773&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33773&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=33773&r=dst IIS Stability: http://bugs.php.net/fix.php?id=33773&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=33773&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=33773&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=33773&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=33773&r=mysqlcfg

« previous php.bugs (#82154) next »