Re: [PHP-DEV] [VOTE] Voting opens for str_starts_with and ends_with functions

2020-03-21 Thread will

On 2020-03-20 14:36, Guilliam Xavier wrote:
On Mon, Jul 22, 2019 at 10:54 AM Nikita Popov  
wrote:


On Fri, Jul 5, 2019 at 4:13 AM  wrote:

> Hello all,
>
> After 15 days of discussion I have opened up voting on the following RFC
> (https://wiki.php.net/rfc/add_str_begin_and_end_functions) .
>
> You can access the voting page here:
> https://wiki.php.net/rfc/add_str_begin_and_end_functions/vote
>
> I have never set up a vote on doku-wiki so please let me know if I made
> the vote incorrectly!
>
> Thanks,
>
> Will
>

As we're already two days past the announced end, I've closed the RFC 
vote.

The final outcome is 26 in favor vs 20 against for str_starts_with and
friends, and 4 in favor to 36 against for mb_starts_with and friends.
Because a 2/3 majority is required, both parts of the proposal are 
declined.


Based on the discussion during voting, I think that trying this again 
with
just str_starts_with+str_ends_with without the case-insensitive 
variants
might pass, as that's where the main controversy seems to be -- though 
some
people also expressed the view that these functions are too trivial to 
add

to the standard library.

In any case, thanks for driving this through the RFC process!

Nikita


Hello Will,

More than 6 months have passed, and in the meantime the related
str_contains RFC has been accepted for the next PHP 8.0
().  Would you be willing to
reboot your RFC with just str_starts_with and str_ends_with (and a
stronger case of how people keep implementing them using the
inefficient and/or error-prone currently available alternatives)?

Best regards,


Yes, I'll start working on that again.

Thanks,

Will

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [VOTE] Voting opens for str_starts_with and ends_with functions

2020-03-20 Thread Guilliam Xavier
On Mon, Jul 22, 2019 at 10:54 AM Nikita Popov  wrote:
>
> On Fri, Jul 5, 2019 at 4:13 AM  wrote:
>
> > Hello all,
> >
> > After 15 days of discussion I have opened up voting on the following RFC
> > (https://wiki.php.net/rfc/add_str_begin_and_end_functions) .
> >
> > You can access the voting page here:
> > https://wiki.php.net/rfc/add_str_begin_and_end_functions/vote
> >
> > I have never set up a vote on doku-wiki so please let me know if I made
> > the vote incorrectly!
> >
> > Thanks,
> >
> > Will
> >
>
> As we're already two days past the announced end, I've closed the RFC vote.
> The final outcome is 26 in favor vs 20 against for str_starts_with and
> friends, and 4 in favor to 36 against for mb_starts_with and friends.
> Because a 2/3 majority is required, both parts of the proposal are declined.
>
> Based on the discussion during voting, I think that trying this again with
> just str_starts_with+str_ends_with without the case-insensitive variants
> might pass, as that's where the main controversy seems to be -- though some
> people also expressed the view that these functions are too trivial to add
> to the standard library.
>
> In any case, thanks for driving this through the RFC process!
>
> Nikita

Hello Will,

More than 6 months have passed, and in the meantime the related
str_contains RFC has been accepted for the next PHP 8.0
().  Would you be willing to
reboot your RFC with just str_starts_with and str_ends_with (and a
stronger case of how people keep implementing them using the
inefficient and/or error-prone currently available alternatives)?

Best regards,

-- 
Guilliam Xavier

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [VOTE] Voting opens for str_starts_with and ends_with functions

2019-07-22 Thread Nikita Popov
On Fri, Jul 5, 2019 at 4:13 AM  wrote:

> Hello all,
>
> After 15 days of discussion I have opened up voting on the following RFC
> (https://wiki.php.net/rfc/add_str_begin_and_end_functions) .
>
> You can access the voting page here:
> https://wiki.php.net/rfc/add_str_begin_and_end_functions/vote
>
> I have never set up a vote on doku-wiki so please let me know if I made
> the vote incorrectly!
>
> Thanks,
>
> Will
>

As we're already two days past the announced end, I've closed the RFC vote.
The final outcome is 26 in favor vs 20 against for str_starts_with and
friends, and 4 in favor to 36 against for mb_starts_with and friends.
Because a 2/3 majority is required, both parts of the proposal are declined.

Based on the discussion during voting, I think that trying this again with
just str_starts_with+str_ends_with without the case-insensitive variants
might pass, as that's where the main controversy seems to be -- though some
people also expressed the view that these functions are too trivial to add
to the standard library.

In any case, thanks for driving this through the RFC process!

Nikita


Re: [PHP-DEV] [VOTE] Voting opens for str_starts_with and ends_with functions

2019-07-10 Thread Claude Pache

> Le 8 juil. 2019 à 18:52, Andrey Andreev  a écrit :
> 
> Hi,
> 
> On Mon, Jul 8, 2019 at 4:54 PM Claude Pache  > wrote:
>> 
>> 
>>> Le 8 juil. 2019 à 15:20, Christoph M. Becker  a écrit :
>>> 
>>> FTR, there is already substr_compare().
>> 
>> `substr_compare()` (as well as `strncmp()` which I am currently using in 
>> lieu of `str_starts_with()`) forces you to provides the substring and the 
>> length of the substring, instead of just the substring:
>> 
>> substr_compare('foobarbaz', 'foo', 0, 3) === 0
>> strncmp('foobarbaz', 'foo', 3) === 0
>> str_starts_with('foobarbaz', 'foo')
>> 
> 
> The existence of substr_compare() and strncmp() is also my main
> motivation for voting No, though I also share Zeev's reasoning.
> 
> You're right that the 2 already existing functions are a bit less
> convenient to use, but the RFC doesn't even try to make a case for
> that, so how do we know this was even considered? While I'm not
> against having more than one way of doing things, I do think we need a
> compelling enough reason to add a third way of doing the same thing
> and here we don't even have an attempt to convince us.
> 
> Cheers,
> Andrey.

The current existing solutions (using `substr()`, `strncmp()`, 
`substr_compare()`, `preg_match()` or whatever) are sufficient—and may even 
look elegant—if you use them once in a blue moon. But if you happen to use them 
frequently, you’ll find soon that they are cumbersome and error-prone compared 
to the prospective `str_starts_with()` and `str_ends_with()`. Concretely:

* Each time I write `strncmp($foo, "bar", 3) === 0`, I spend a few seconds to 
double-check the number of bytes in "bar".

* Not later than yesterday, I spent one minute in order to find why 
`substr_compare($file, ".css", -3) === 0` didn’t do what I meant. Note also 
that the alternative `substr($file, -3) === ".css"` suffers from the same 
issue, and that the alternative `preg_match('/\\.css$/', $file)` requires you 
to not forget to escape special characters.

Checking whether a string begins, respectively ends, with some substring is a 
relatively common task for some programmers. The issue is that, although they 
have already plenty of ways to do that, none of them is natural and all of them 
have issues.

But indeed, the RFC text fails to discuss the various existing alternatives and 
their downsides.

—Claude



Re: [PHP-DEV] [VOTE] Voting opens for str_starts_with and ends_with functions

2019-07-09 Thread Claude Pache



> Le 9 juil. 2019 à 09:40, Peter Bowyer  a écrit :
> 
> On Mon, 8 Jul 2019 at 19:09, Björn Larsson 
> wrote:
> 
>> Having this _ci postfix is  a new way of indicating case insensitivity.
>> I think that it might add to negative votes. Personally I think it's a
>> good idea to mimic existing ways, even if they are a bit awkward.
>> 
>> How about using a flag or following "tradition", like stri_starts_with
>> & stri_ends_with or str_istarts_with & str_iends_with? That would
>> follow strstr / stristr and str_replace / str_ireplace.
>> 
> 
> I would vote yes with that naming. It's a damn silly tradition, but it's
> what PHP uses for other functions, and keeping consistency is better than
> improving individual functions.
> 
> Peter

There are currently (at least) two ways for marking case insensitivity in the 
name: the character “i” as in stripos() and  the substring “case” as in: 
strcasecmp().

Adding a third way, namely the “ci” suffix (or, even worse, a flag) is 
absolutely in the silly tradition of inconsistent naming of PHP functions 
(although admittedly not one we should strive to maintain)... except that “ci” 
is maybe more meaningful than “i” and “case”.

—Claude
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [VOTE] Voting opens for str_starts_with and ends_with functions

2019-07-09 Thread Peter Bowyer
On Mon, 8 Jul 2019 at 19:09, Björn Larsson 
wrote:

> Having this _ci postfix is  a new way of indicating case insensitivity.
> I think that it might add to negative votes. Personally I think it's a
> good idea to mimic existing ways, even if they are a bit awkward.
>
> How about using a flag or following "tradition", like stri_starts_with
> & stri_ends_with or str_istarts_with & str_iends_with? That would
> follow strstr / stristr and str_replace / str_ireplace.
>

I would vote yes with that naming. It's a damn silly tradition, but it's
what PHP uses for other functions, and keeping consistency is better than
improving individual functions.

Peter


Re: [PHP-DEV] [VOTE] Voting opens for str_starts_with and ends_with functions

2019-07-08 Thread will

On 2019-07-08 17:52, Ben Ramsey wrote:
On Jul 8, 2019, at 13:09, Björn Larsson  
wrote:


Having this _ci postfix is  a new way of indicating case 
insensitivity.

I think that it might add to negative votes. Personally I think it's a
good idea to mimic existing ways, even if they are a bit awkward.

How about using a flag or following "tradition", like stri_starts_with
& stri_ends_with or str_istarts_with & str_iends_with? That would
follow strstr / stristr and str_replace / str_ireplace.

I have no voting rights though.



I made this recommendation earlier in the other thread
(), but it didn’t get any
traction or response:


maybe the signatures could be revised to pass a third parameter?

str_starts_with($haystack, $needle, $case_sensitive = true): bool


Since voting has already begun, is this something that could still be
considered?

-Ben


Thanks for the interest everyone! I've been following the email thread 
and have a few thoughts.


- At one point I had it set to take case sensitivity as a parameter 
(https://github.com/php/php-src/pull/2049/commits/f89d8edc5f32d8a4b702699209e72d864e2ca440). 
That isn't a bad idea IMO. I changed it to have split functions to match 
str_ireplace, stripos, etc.


- I agree the *_ci naming convention is different than most of the 
existing codebase, but a lot of discussion during the process led to the 
*_ci naming convention. And while the *_ci naming convention isn't 
traditional, it does seem more intuitive. The i is easier to read in 
something short like "str_ireplace" but kind of gets lost in something 
long like "str_istarts_with".


- I'd considered splitting the vote into 3 parts:
 1) str_starts_with and str_ends_with
 2) str_starts_with_ci and str_ends_with_ci
 3) The mb_* functions.

 But I decided against that as I felt that might be overly splitting 
up the proposal.


If the main issue is naming and not functionality, I am happy to rework 
the RFC (if it fails) to be more palatable. I primarily would like to 
add this functionality to PHP, regardless of the naming. In my opinion 
one of the nice things about PHP is that it comes with so many things 
under the hood. As a user of the language that is something I 
appreciate. A lot of powerful functionality is baked into the language 
and that functionality is available on almost every web host. A language 
like Python or Java just can't compare in that respect. Even NodeJS 
requires an extensive amount of packages to accomplish even simple 
tasks. PHP is nice because it ships with "batteries" included. Sure, 
that brings some issues along with it, but that is as much a strength of 
the language as it is a challenge. Adding a common task like starts_with 
and ends_with seems like a reasonable thing to do.


Thanks,

Will

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [VOTE] Voting opens for str_starts_with and ends_with functions

2019-07-08 Thread Ben Ramsey
> On Jul 8, 2019, at 13:09, Björn Larsson  wrote:
> 
> Having this _ci postfix is  a new way of indicating case insensitivity.
> I think that it might add to negative votes. Personally I think it's a
> good idea to mimic existing ways, even if they are a bit awkward.
> 
> How about using a flag or following "tradition", like stri_starts_with
> & stri_ends_with or str_istarts_with & str_iends_with? That would
> follow strstr / stristr and str_replace / str_ireplace.
> 
> I have no voting rights though.


I made this recommendation earlier in the other thread 
(), but it didn’t get any traction 
or response:

> maybe the signatures could be revised to pass a third parameter?
> 
> str_starts_with($haystack, $needle, $case_sensitive = true): bool

Since voting has already begun, is this something that could still be 
considered?

-Ben


signature.asc
Description: Message signed with OpenPGP


Re: [PHP-DEV] [VOTE] Voting opens for str_starts_with and ends_with functions

2019-07-08 Thread Björn Larsson

Den 2019-07-07 kl. 22:45, skrev Theodore Brown:


On Thu, July 4, 2019 at 9:13 PM Will  wrote:


Hello all,

After 15 days of discussion I have opened up voting on the following
RFC (https://wiki.php.net/rfc/add_str_begin_and_end_functions).


Thank you for your work on this. I'm surprised that so far the vote
is so controversial, with 8 votes in favor and 8 opposed.

For those voting against adding these functions, can you clarify why?
Do you dislike how they are named, or do you not see the need for the
case insensitive versions, or is there an issue with the implementation?

Personally I'd find the basic `str_starts_with` and `str_ends_with`
functions very valuable. Currently I either have to implement functions
like this myself in almost every script, or else write repetitious
code like the following:

```php
$needle = "foobar";

if (substr($haystack, 0, strlen($needle)) === $needle) {
 // starts with "foobar"
}
```

To avoid repetition, many developers use the following pattern instead:

```php
if (strpos($haystack, "foobar") === 0) {
 // starts with "foobar"
}
```

However, with longer strings this becomes far less efficient, since PHP
has to search through the entire haystack to find the needle position.

If this RFC is accepted, these awkward and inefficient approaches
could be replaced with straightforward and fast code like this:

```php
if (str_starts_with($haystack, "foobar")) {
 // ...
}
```

Please vote on the RFC if you haven't already. Clarification would be
appreciated if don't feel that these functions would be a good addition.

Best regards,
Theodore

Hi,

Having this _ci postfix is  a new way of indicating case insensitivity.
I think that it might add to negative votes. Personally I think it's a
good idea to mimic existing ways, even if they are a bit awkward.

How about using a flag or following "tradition", like stri_starts_with
& stri_ends_with or str_istarts_with & str_iends_with? That would
follow strstr / stristr and str_replace / str_ireplace.

I have no voting rights though.

r//Björn L

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [VOTE] Voting opens for str_starts_with and ends_with functions

2019-07-08 Thread Theodore Brown
On Mon, July 8, 2019 at 9:10 AM Sara Golemon  wrote:

> On Sun, Jul 7, 2019 at 3:45 PM Theodore Brown  wrote:
> 
> > For those voting against adding these functions, can you clarify why?
> 
> Explaining my non-vote. I'm explicitly abstaining as I don't see the
> value in these functions (I'd rather see a community driven library
> which does the same thing in a more agile way), but neither do I see
> much intrinsic harm in allowing these functions in.

Thanks Sara. I understand your perspective of not wanting to add more
functions to PHP core which can be easily implemented in userland.

However, when it comes to basic string functions which are needed in
almost every script, I don't think it makes sense to ask users to
depend on an extra library for this. Almost every other language
has built-in functions for simply checking if a string starts or ends
with another string.

Best regards,
Theodore
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [VOTE] Voting opens for str_starts_with and ends_with functions

2019-07-08 Thread Sara Golemon
On Sun, Jul 7, 2019 at 3:45 PM Theodore Brown 
wrote:
> For those voting against adding these functions, can you clarify why?
>
Explaining my non-vote.  I'm explicitly abstaining as I don't see the value
in these functions (I'd rather see a community driven library which does
the same thing in a more agile way), but neither do I see much intrinsic
harm in allowing these functions in.

I did vote against the mb* variants as I'd like to see those die in favor
of ext/intl in all ways and every way.

-Sara


Re: [PHP-DEV] [VOTE] Voting opens for str_starts_with and ends_with functions

2019-07-07 Thread Theodore Brown
On Thu, July 4, 2019 at 9:13 PM Will  wrote:

> Hello all,
>
> After 15 days of discussion I have opened up voting on the following
> RFC (https://wiki.php.net/rfc/add_str_begin_and_end_functions).


Thank you for your work on this. I'm surprised that so far the vote
is so controversial, with 8 votes in favor and 8 opposed.

For those voting against adding these functions, can you clarify why?
Do you dislike how they are named, or do you not see the need for the
case insensitive versions, or is there an issue with the implementation?

Personally I'd find the basic `str_starts_with` and `str_ends_with`
functions very valuable. Currently I either have to implement functions
like this myself in almost every script, or else write repetitious
code like the following:

```php
$needle = "foobar";

if (substr($haystack, 0, strlen($needle)) === $needle) {
// starts with "foobar"
}
```

To avoid repetition, many developers use the following pattern instead:

```php
if (strpos($haystack, "foobar") === 0) {
// starts with "foobar"
}
```

However, with longer strings this becomes far less efficient, since PHP
has to search through the entire haystack to find the needle position.

If this RFC is accepted, these awkward and inefficient approaches
could be replaced with straightforward and fast code like this:

```php
if (str_starts_with($haystack, "foobar")) {
// ...
}
```

Please vote on the RFC if you haven't already. Clarification would be
appreciated if don't feel that these functions would be a good addition.

Best regards,
Theodore
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [VOTE] Voting opens for str_starts_with and ends_with functions

2019-07-05 Thread Nikita Popov
On Fri, Jul 5, 2019 at 6:17 AM Theodore Brown 
wrote:

> On Thu, July 4, 2019 at 9:13 PM Will  wrote:
>
> > After 15 days of discussion I have opened up voting on the following RFC
> > (https://wiki.php.net/rfc/add_str_begin_and_end_functions) .
> >
> > You can access the voting page here:
> > https://wiki.php.net/rfc/add_str_begin_and_end_functions/vote
> >
> > I have never set up a vote on doku-wiki so please let me know if I made
> > the vote incorrectly!
>
> It seems really unusual for voting to be on a separate page than the
> RFC. Can you move the doodle voting macro to a "Vote" section on the
> main RFC page?
>
> Thanks,
> Theodore


I've taken the liberty to move the voting widgets onto the main RFC page,
the new voting link is:
https://wiki.php.net/rfc/add_str_begin_and_end_functions#vote

I've also move the RFC into the voting section on the RFC overview page.

Nikita


Re: [PHP-DEV] [VOTE] Voting opens for str_starts_with and ends_with functions

2019-07-05 Thread Peter Cowburn
On Fri, 5 Jul 2019 at 05:17, Theodore Brown  wrote:

> On Thu, July 4, 2019 at 9:13 PM Will  wrote:
>
> > After 15 days of discussion I have opened up voting on the following RFC
> > (https://wiki.php.net/rfc/add_str_begin_and_end_functions) .
> >
> > You can access the voting page here:
> > https://wiki.php.net/rfc/add_str_begin_and_end_functions/vote
> >
> > I have never set up a vote on doku-wiki so please let me know if I made
> > the vote incorrectly!
>
> It seems really unusual for voting to be on a separate page than the
> RFC. Can you move the doodle voting macro to a "Vote" section on the
> main RFC page?
>

Further to this, please follow the instructions at
https://wiki.php.net/rfc/howto. It has simple to follow steps detailing
exactly what to do.
Also, this RFC is *still* showing as "inactive" on the RFC list (
https://wiki.php.net/rfc) - anyone watching that page won't even know it
was back under discussion never mind in voting.


>
> Thanks,
> Theodore
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP-DEV] [VOTE] Voting opens for str_starts_with and ends_with functions

2019-07-04 Thread Theodore Brown
On Thu, July 4, 2019 at 9:13 PM Will  wrote:

> After 15 days of discussion I have opened up voting on the following RFC 
> (https://wiki.php.net/rfc/add_str_begin_and_end_functions) .
>
> You can access the voting page here: 
> https://wiki.php.net/rfc/add_str_begin_and_end_functions/vote
>
> I have never set up a vote on doku-wiki so please let me know if I made 
> the vote incorrectly!

It seems really unusual for voting to be on a separate page than the
RFC. Can you move the doodle voting macro to a "Vote" section on the
main RFC page?

Thanks,
Theodore
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] [VOTE] Voting opens for str_starts_with and ends_with functions

2019-07-04 Thread will

Hello all,

After 15 days of discussion I have opened up voting on the following RFC 
(https://wiki.php.net/rfc/add_str_begin_and_end_functions) .


You can access the voting page here: 
https://wiki.php.net/rfc/add_str_begin_and_end_functions/vote


I have never set up a vote on doku-wiki so please let me know if I made 
the vote incorrectly!


Thanks,

Will

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php