Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread Mike Schinkel
> On Sep 2, 2020, at 5:54 PM, Stanislav Malyshev wrote: > > Hi! > >>> In theory, this should be a general performance win any time one >>> needs to iterate over only the keys of an iterable, because it does >>> not require the use of an O(n) iteration and building of the array >>> that array_key

Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread tyson andre
Hi Benas IML, > I'd also like to mention that other languages don't have any kind of > syntactic sugar/special syntax for iterating over keys. That is achieved > using a function though. That's not true, Golang has iterating over keys by default and a more verbose syntax to iterate over values.

Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread Stanislav Malyshev
Hi! >> In theory, this should be a general performance win any time one >> needs to iterate over only the keys of an iterable, because it does >> not require the use of an O(n) iteration and building of the array >> that array_keys() would, plus it works on non-array types (such as >> generators o

Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread Olle Härstedt
On Wed, 2 Sep 2020, 21:54 Dik Takken, wrote: > On 02-09-2020 21:31, Dik Takken wrote: > > Even if we decide that it is not worth the trouble for foreach loops, > > there are other cases where this new syntax can work well. Array > > destructuring has already been mentioned. > > Replying to myself

Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread Josh Bruce
> On Sep 2, 2020, at 12:05 PM, Michael Voříšek - ČVUT FEL > wrote: > > I like "void", as "null" can be ambiguous. > > Imagine function example($a = 'default value 1', $b = 'default value 2') {} > > With "void", we can allow skipping arguments in advance to the default > pamameter value like

Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread Dik Takken
On 02-09-2020 21:31, Dik Takken wrote: > Even if we decide that it is not worth the trouble for foreach loops, > there are other cases where this new syntax can work well. Array > destructuring has already been mentioned. Replying to myself: It just occurred to me that array destructuring already

Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread Dik Takken
On 02-09-2020 19:13, Nikita Popov wrote: > Just like the first time this was discussed, I don't think this RFC makes a > sufficient case on why we need explicit syntax for this. Just ignoring the > value is an existing pattern that works across all PHP versions: > > foreach ($iterable as $key

Re: [PHP-DEV] Pass source object to clone like __clone($origThis)

2020-09-02 Thread David Rodrigues
I understand... seems that `$this` is very confusing inside `__clone()`: when writing, it writes to the clone, when reading it reads from original. Seems valid a new optional parameter definition with the original source. Atenciosamente, David Rodrigues Em qua., 2 de set. de 2020 às 15:41, Mi

Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread Chase Peeler
On Wed, Sep 2, 2020 at 1:13 PM Nikita Popov wrote: > On Wed, Sep 2, 2020 at 5:16 AM Mike Schinkel wrote: > > > This is a new thread for John Bafford's RFC which he mentioned on another > > thread, see below: > > > > https://wiki.php.net/rfc/foreach_void < > > https://wiki.php.net/rfc/foreach_voi

[PHP-DEV] Pass source object to clone like __clone($origThis)

2020-09-02 Thread Michael Voříšek - ČVUT FEL
Hi, please look at https://stackoverflow.com/questions/63675888/get-original-source-instance-in-clone do you have anything against updating PHP to pass "instance before cloned" to any __clone call from php? no BC - user may accept this extra argument or declare function __clone() without any

Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread Benas IML
+1. I'd also like to mention that other languages don't have any kind of syntactic sugar/special syntax for iterating over keys. That is achieved using a function though. This proposal to me seems a bit like the "return if/guard" RFC i. e. I see no value in it. On Wed, Sep 2, 2020, 8:13 PM Nikit

Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread Nikita Popov
On Wed, Sep 2, 2020 at 5:16 AM Mike Schinkel wrote: > This is a new thread for John Bafford's RFC which he mentioned on another > thread, see below: > > https://wiki.php.net/rfc/foreach_void < > https://wiki.php.net/rfc/foreach_void> > Just like the first time this was discussed, I don't think t

Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread Michael Voříšek - ČVUT FEL
I like "void", as "null" can be ambiguous. Imagine function example($a = 'default value 1', $b = 'default value 2') {} With "void", we can allow skipping arguments in advance to the default pamameter value like example(void, 'test');. With kind regards / Mit freundlichen Grüßen / S přátels

Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread Arvids Godjuks
On Wed, 2 Sep 2020 at 18:58, Ben Ramsey wrote: > > > On Sep 2, 2020, at 11:14, Lester Caine wrote: > > > > On 02/09/2020 15:31, Thomas Bley wrote: > >> I'd also like to propose to use null: > >> [null, null, $username] = getUserData(); > >> foreach ($source as $key => null) {} > > > > Exactly w

Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread Ben Ramsey
> On Sep 2, 2020, at 11:14, Lester Caine wrote: > > On 02/09/2020 15:31, Thomas Bley wrote: >> I'd also like to propose to use null: >> [null, null, $username] = getUserData(); >> foreach ($source as $key => null) {} > > Exactly what null is designed for ... I second (or third) `null`. Over

Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread Sara Golemon
On Wed, Sep 2, 2020 at 9:31 AM Thomas Bley wrote: > Hello, > > I'd also like to propose to use null: > > [null, null, $username] = getUserData(); > > foreach ($source as $key => null) {} > > These both look like great, expressive syntaxes. No new keywords, no major change to existing idioms, jus

Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread Lester Caine
On 02/09/2020 15:31, Thomas Bley wrote: I'd also like to propose to use null: [null, null, $username] = getUserData(); foreach ($source as $key => null) {} Exactly what null is designed for ... -- Lester Caine - G8HFL - Contact - https://lsces.uk/wiki/Contact L.S.

Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread Thomas Bley
Hello, I'd also like to propose to use null: [null, null, $username] = getUserData(); foreach ($source as $key => null) {} Regards Thomas > David Rodrigues hat am 02.09.2020 16:24 geschrieben: > > > I think "void" is a good solution and is very clear, compared to "_". > > [void, void, $us

Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread David Rodrigues
I think "void" is a good solution and is very clear, compared to "_". [void, void, $username] = getUserData(); Atenciosamente, David Rodrigues Em qua., 2 de set. de 2020 às 10:57, Dik Takken escreveu: > On 02-09-2020 15:35, Chase Peeler wrote: > > Isn't the underscore an alias for gettext()?

Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread Dik Takken
On 02-09-2020 15:35, Chase Peeler wrote: > Isn't the underscore an alias for gettext()? You are right, it is. Now this does not necessarily mean that underscore cannot be used for ignored variables. Depending on the context in which it is used an underscore may or may not be ambiguous. Since we a

Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread Chase Peeler
On Wed, Sep 2, 2020 at 9:16 AM Josh Bruce wrote: > > > On Sep 2, 2020, at 6:27 AM, Dik Takken wrote: > > > > On 02-09-2020 12:48, Olle Härstedt wrote: > >> An alternative syntax would be > >> > >>foreach($iterable as $key => _) { ... } > >> > >> Using underscore as a way to signal "I don't

Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread Josh Bruce
> On Sep 2, 2020, at 6:27 AM, Dik Takken wrote: > > On 02-09-2020 12:48, Olle Härstedt wrote: >> An alternative syntax would be >> >>foreach($iterable as $key => _) { ... } >> >> Using underscore as a way to signal "I don't care about this value". >> Same could be possible with list dest

Re: [PHP-DEV] [VOTE] Shorter Attributes Syntax Change

2020-09-02 Thread Derick Rethans
Hi, This vote has now been concluded. The primary vote to re-choose with STV was accepted, with 50 for and 11 against. The STV selection selected the syntax: #[Attr] The full STV run is at https://gist.github.com/3c1f41afbabdeaa0c12753397833db8c Thanks all for participating and votin

Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread Dik Takken
On 02-09-2020 12:48, Olle Härstedt wrote: > An alternative syntax would be > > foreach($iterable as $key => _) { ... } > > Using underscore as a way to signal "I don't care about this value". > Same could be possible with list destructoring, like > > [_, _, $something] = foo(); > > This

Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values

2020-09-02 Thread Olle Härstedt
An alternative syntax would be foreach($iterable as $key => _) { ... } Using underscore as a way to signal "I don't care about this value". Same could be possible with list destructoring, like [_, _, $something] = foo(); This syntax comes from OCaml. Possibly other languages, too? Not s