The $count parameter in the PHP function str_ireplace() is passed by
reference and is updated with the number of replacements made by the
function. The $count parameter in JString::str_ireplace() is used to
limit the number of replacements that can be made. This seems like a
major divergance in functionality...
This is the test I ran:
$subject = "ABCDEFABCDEF";
$search = "D";
$replace = ".";
$count = 1;
var_dump(JString::str_ireplace($search, $replace, $subject, $count));
var_dump($count);
var_dump(str_ireplace($search, $replace, $subject, $count));
var_dump($count);
And this is the result:
string 'ABC.EFABCDEF' (length=12)
int 1
string 'ABC.EFABC.EF' (length=12)
int 2
Notice that the result is different and so is the ultimate value of
$count.
There is a problem in that we cannot pass $count (an integer) by
reference (as in the PHP function) - I would have thought the best
solution would be to remove the $count parameter?
--
You received this message because you are subscribed to the Google Groups "Joomla! Framework Development" group.
To post to this group, send an email to joomla-dev...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-frame...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-framework?hl=en-GB.
> > joomla-dev-frame...@googlegroups.com<joomla-dev-framework%2Bunsu...@googlegroups.com>
To unsubscribe from this group, send email to joomla-dev-frame...@googlegroups.com.
@Ian:
Perhaps I too am having an off day... but I didn't think that you
could pass primitives by reference?
On Apr 12, 12:34 am, Mark Dexter <dextercow...@gmail.com> wrote:
> Hi. I did some more testing and confirmed that this is indeed the case. I
> propose that we change the documentation as follows:
>
> @param int optional count value to limit the number of replacements
>
> and change the unit tests to test this parameter. I've got a local change to
> this effect that I can commit if you agree. Thanks. Mark
>
> On Sun, Apr 11, 2010 at 4:29 PM, Mark Dexter <dextercow...@gmail.com> wrote:
> > I *think* the problem is that the $count variable doesn't do what it says
> > in the doc block. Looking at the code, it appears that the count variable
> > limits the number of replaces instead of counting them. So I think we can
> > either change the documentation and the unit tests or try to fix the
> > function to actually return the number of replacements. Mark
>
> >>> joomla-dev-frame...@googlegroups.com<joomla-dev-framework%2Bunsu...@googlegroups.com>
> >>> .
>
> >>> For more options, visit this group at
> >>>http://groups.google.com/group/joomla-dev-framework?hl=en-GB.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Joomla! Framework Development" group.
> >> To post to this group, send an email to
> >> joomla-dev...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> joomla-dev-frame...@googlegroups.com<joomla-dev-framework%2Bunsu...@googlegroups.com>
I would be in favour of aligning it, all it takes is the addition of a
& in the params and the relevant code to update it. It is a
functionality change however but it is bringing it in line with PHP's
function call and I feel that would be acceptable.
Sam Moffatt
http://pasamio.id.au
> To unsubscribe from this group, send email to joomla-dev-frame...@googlegroups.com.
Many of JString methods look to depend on the 3rd party library
http://phputf8.sourceforge.net. I had a peek at the latest release and
the issue still exists. It also looks as though the project has lost
momentum there hasn't been any activity in an age.
However I did come across an alternative library http://docs.kohanaphp.com/core/utf8.
This includes some rather nice looking UTF-8 aware string functions
and it also looks to be written by the same person Harry Fuecks (it's
amazing how often his name crops up!). Perhaps we should be
considering a change to this (or a similar, more up-to-date) library
for UTF-8 string functions?
just a thought...
Note I am assuming that this method is still required since Kohana
includes it and Kohana is a PHP5 library.
On 12 Apr, 16:35, Ian MacLennan <ian.maclen...@joomla.org> wrote:
> Do we need this method anymore? How does the core str_ireplace work? Does
> it handle UTF8 okay? If it does, I would simply deprecate this and leave
> it.
>
> Ian
>
> On Mon, Apr 12, 2010 at 11:23 AM, Mark Dexter <dextercow...@gmail.com>wrote:
>
> > Well, if we want to change how the method works, that's fine. As I said,
> > right now that parameter can be used to limit the number of substitutions.
> > If someone wants to make a patch to change the way the method works to
> > return a count of substitutions instead, that's fine with me. Mark
>
> >> <joomla-dev-framework%2Bunsu...@googlegroups.com<joomla-dev-framework%252Buns...@googlegroups.com>
>
> >> >> >>> .
>
> >> >> >>> For more options, visit this group at
> >> >> >>>http://groups.google.com/group/joomla-dev-framework?hl=en-GB.
>
> >> >> >> --
> >> >> >> You received this message because you are subscribed to the Google
> >> Groups
> >> >> >> "Joomla! Framework Development" group.
> >> >> >> To post to this group, send an email to
> >> >> >> joomla-dev...@googlegroups.com.
> >> >> >> To unsubscribe from this group, send email to
> >> >> >> joomla-dev-frame...@googlegroups.com<joomla-dev-framework%2Bunsu...@googlegroups.com>
> >> <joomla-dev-framework%2Bunsu...@googlegroups.com<joomla-dev-framework%252Buns...@googlegroups.com>