On 2016-08-02 18:44, Yasuo Ohgaki wrote:
> Hi David,
>
> On Tue, Aug 2, 2016 at 10:36 AM, David Rodrigues
> <david.proweb@gmail.com> wrote:
>> Sara Golemon wrote:
>>> Feeling "meh" on it (neither for nor against), but I would consider
>>> consistency with other str*() functions by making case-insensitivity
>>> live in separate functions rather than as a parameter. e.g.
>>> str_begins(), str_ibegins(), str_ends(), end_iends()
>>
>> I guess that "i" isn't appliable when it have slashes.
>> In this case, functions should be: strbegins, stribegins, strends,
>> striends.
>> In all case, I think that is better a third parameter and keep
>> underlined.
>
> This is difficult issue.
> String function names are inconsistent currently.
> It is better to stick to CODING_STANDARDS naming convention for new
> function names. Therefore, new string functions are better to be named
> str_*() unless they are too strange.
>
> e.g.
> http://php.net/manual/en/function.str-replace.php
> http://php.net/manual/en/function.str-ireplace.php
>
> I would like to fix function name inconsistencies by having aliases in
> near future.
> https://wiki.php.net/rfc/consistent_function_names
>
> It might be okay to have "s" in function names, but if we want to be
> consistent,
>
> str_replace -> str_replaces
> str_ireplace -> str_ireplaces
>
> IMO, following names are better for consistency.
>
> str_begin
> str_ibegin
> str_end
> str_iend
>
> In addition, str_replace() has seach_value at first, so signature might
> be
>
> boolean str_begin(string $search_value, string $str, [boolean
> $case_sensitive = true])
> boolean str_end(string $search_value, string $str, string
> $search_value [boolean $case_sensitive = true])
>
> However, strstr() (and other str functions without "_". e.g.
> strpos/stripos/strrpos/strripos) has search_value as the 2nd
> parameter. If we follow this format, current signature is fine.
>
> It may be better sort out and fix consistency issues first, then add
> new functions. Otherwise, we may introduce more consistency issues.
>
> Regards,
>
> BTW, having "i" is more readable.
>
> str_ibegin("searchthis", $str);
> is more readable than
> str_begin("seachthis", $str, TRUE);
> as programmer does not have to know that's the TRUE means.
> It's small thing, but small things add up.
>
> --
> Yasuo Ohgaki
> yohgaki@ohgaki.net
Everyone has raised important considerations. For me, the most important
thing is maintaining consistency with the existing PHP string library. I
do not want these functions to feel "tacked" on, as if they were
haphazardly added to PHP. If these functions are added to the language,
it should feel as if they have always been a part of the language (even
if they haven't been). This consistency is important in order to ensure
these functions ADD to PHP instead of just cluttering it up.
Having separate functions for case sensitivity makes sense, that is much
more consistent with the existing string library. I think the proposal
should be amended to separate those two functionalities. I think like
having an "s" at the end of the function names reads better, but
omitting the "s" fits better with the existing function names and does
not read bad. Therefore, I am in favor of dropping the "s".
As far as str_begin vs strbegin, I think str_begin is more readable.
Therefore, I think it would be better to implement:
boolean str_begin(string $search_value, string $str)
boolean str_ibegin(string $search_value, string $str)
boolean str_end(string $search_value, string $str)
boolean str_iend(string $search_value, string $str)
This is much more consistent with the existing string library.
Regards,
Will