#44794 [Opn->WFx]: Inconsistent order of argument for strtr compared to str_replace

From: Date: Tue, 22 Apr 2008 12:40:06 +0000
Subject: #44794 [Opn->WFx]: Inconsistent order of argument for strtr compared to str_replace
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-124422@lists.php.net to get a copy of this message
 ID:          44794
 Updated by:  iliaa@php.net
 Reported By: php dot net at mog dot se
-Status:      Open
+Status:      Wont fix
 Bug Type:    Strings related
 PHP Version: 5.2.5
 New Comment:

Any changes here will introduce massive BC breaks.


Previous Comments:
------------------------------------------------------------------------

[2008-04-21 17:56:32] php dot net at mog dot se

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 this bug report at http://bugs.php.net/?id=44794&edit=1



Thread (8 messages)

« previous php.bugs (#124422) next »