ID:              44794
 User updated by: php dot net at mog dot se
 Reported By:     php dot net at mog dot se
 Status:          Wont fix
 Bug Type:        Strings related
 PHP Version:     5.2.5
 New Comment:

iliaa, yes, i already stated that in my description. That's why i
suggested adding a new function which is not inconsistent, and then the
old function would be kept for backwards compatibility only.

Does the PHP team not care about API consistency or why was the bug
closed with so little discussion?

If an acceptable solution can be agreed upon i would be happy to write
a patch myself.

Regards,
Morgan


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

[2008-04-22 12:40:06] [EMAIL PROTECTED]

Any changes here will introduce massive BC breaks.

------------------------------------------------------------------------

[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

Reply via email to