From: paulschreiber at gmail dot com Operating system: any PHP version: 4.4.4 PHP Bug Type: Strings related Bug description: ER: Allow str_replace with string subject, array replace
Description: ------------ The PHP docs for str_replace say: "If search and replace are arrays, then str_replace() takes a value from each array and uses them to do search and replace on subject. If replace has fewer values than search, then an empty string is used for the rest of replacement values. If search is an array and replace is a string, then this replacement string is used for every value of search. The converse would not make sense, though." I think the converse makes sense in some cases. Here is an example: $result = str_replace("?", array("Joe", "Smith"), "SELECT * FROM people WHERE first = ? AND last = ?"); (Yes, if you were doing real database work, you'd need to escape everything.) It would be nice if PHP supported this. Reproduce code: --------------- $result = str_replace("?", array("'Joe'", "'Smith'"), "SELECT * FROM people WHERE first = ? AND last = ?"); print $result; Expected result: ---------------- SELECT * FROM people WHERE first = 'Joe' AND last = 'Smith' Actual result: -------------- PHP Notice: Array to string conversion in /Users/paul/- on line 2 Notice: Array to string conversion in /Users/paul/- on line 2 SELECT * FROM people WHERE first = Array AND last = Array -- Edit bug report at http://bugs.php.net/?id=38685&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=38685&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=38685&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=38685&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=38685&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=38685&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=38685&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=38685&r=needscript Try newer version: http://bugs.php.net/fix.php?id=38685&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=38685&r=support Expected behavior: http://bugs.php.net/fix.php?id=38685&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=38685&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=38685&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=38685&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38685&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=38685&r=dst IIS Stability: http://bugs.php.net/fix.php?id=38685&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=38685&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=38685&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=38685&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=38685&r=mysqlcfg