From: php dot net at mog dot se Operating system: PHP version: 5.2.5 PHP Bug Type: Strings related Bug description: Inconsistent order of argument for strtr compared to str_replace
Description: ------------ The similar but different string replacement functions str_replace strtr() have an inconsistent order of arguments, in strtr() $subject is the first argument and in str_replace it is the last. strtr($subject, $search, $replace) str_replace($from, $to, $subject) There is no logic in this behaviour so every time i use these functions i have to look them up to find out which is which. There is no backwards compatible way to fix this as all arguments can be strings, so new API functions would be needed while keeping strtr and str_replace as is. The PHP API desparatley needs a naming convention and this IMO is one of it's worst examples. Expected result: ---------------- Without an obvious fix i can only offer my ideas on how to fix this: #1 Adding a str_translate($from, $to, $subject) method would be possible, assuming that this order is consistent with the rest of PHP's API #2 A solution which is very logical & consistent would be if strings acted like objects, then $subject->replace($from, $to) and $subject->translate($from, $to) would be possible. My guess would be that treating strings as objects would not be a clean implementation, but perhaps an OO version of string is possible in SPL. -- Edit bug report at http://bugs.php.net/?id=44794&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44794&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44794&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44794&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=44794&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=44794&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=44794&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=44794&r=needscript Try newer version: http://bugs.php.net/fix.php?id=44794&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=44794&r=support Expected behavior: http://bugs.php.net/fix.php?id=44794&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=44794&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=44794&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=44794&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44794&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=44794&r=dst IIS Stability: http://bugs.php.net/fix.php?id=44794&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=44794&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=44794&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=44794&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=44794&r=mysqlcfg
