Hey,
Thanks for all your feedback in the discussion thread!
So, before I start the vote, just two quick notes:
I've added two notes about the statement syntax and the single variable use.
Though a few people complained, I'm not switching to the ==> operator, as I noticed many people expected typehints to work (they don't due to parser limitations) when they compared to Hack's short Closures. It also allows us to differ syntax-wise [e.g. for typehints] from Hack without causing any confusion later. Which should be the smartest choice: Avoid conflicts. (If anyone strongly feels against that, he may vote no, but I would like to not bikeshed that in this Vote thread, but leave it free for eventual actual issues.)
Now, the link to the RFC about Short Closures:
https://wiki.php.net/rfc/short_closures
or straight ahead to the vote:
https://wiki.php.net/rfc/short_closures#vote
Thanks,
Bob
I'm against the magic - "automatically use () all of the (compiled)
variables".
I'm also against compound short closures with curly brackets.
in my opinion they opens too many ambiguous questions.
function foo() {
(($x) ~> {$y = 3; return $y + $x;})(5);
return $y;
}
also think about nested closures and use of variables from not direct
enclosure.
I'm not sure if we need all "functional programming" features in PHP, but
if we introduce them, lets do it consistently with the existing language.
I think, this proposal can't be approved without support for type hinting.
Thanks. Dmitry.
Hey,
Thanks for all your feedback in the discussion thread!
So, before I start the vote, just two quick notes:
I've added two notes about the statement syntax and the single variable
use.
Though a few people complained, I'm not switching to the ==> operator, as
I noticed many people expected typehints to work (they don't due to parser
limitations) when they compared to Hack's short Closures. It also allows us
to differ syntax-wise [e.g. for typehints] from Hack without causing any
confusion later. Which should be the smartest choice: Avoid conflicts. (If
anyone strongly feels against that, he may vote no, but I would like to not
bikeshed that in this Vote thread, but leave it free for eventual actual
issues.)Now, the link to the RFC about Short Closures:
https://wiki.php.net/rfc/short_closures
or straight ahead to the vote:
https://wiki.php.net/rfc/short_closures#voteThanks,
Bob
I'd really like to understand what you're trying to say there Dmitry, but I
don't get it.
What is your example function trying to show ?
As it mentions in the RFC, vars in short closure are by-value, so I can't
see what side effects you might be thinking of ?
Cheers
Joe
I'm against the magic - "automatically use () all of the (compiled)
variables".
I'm also against compound short closures with curly brackets.
in my opinion they opens too many ambiguous questions.function foo() {
(($x) ~> {$y = 3; return $y + $x;})(5);
return $y;
}also think about nested closures and use of variables from not direct
enclosure.I'm not sure if we need all "functional programming" features in PHP, but
if we introduce them, lets do it consistently with the existing language.
I think, this proposal can't be approved without support for type hinting.Thanks. Dmitry.
Hey,
Thanks for all your feedback in the discussion thread!
So, before I start the vote, just two quick notes:
I've added two notes about the statement syntax and the single variable
use.
Though a few people complained, I'm not switching to the ==> operator, as
I noticed many people expected typehints to work (they don't due to
parser
limitations) when they compared to Hack's short Closures. It also allows
us
to differ syntax-wise [e.g. for typehints] from Hack without causing any
confusion later. Which should be the smartest choice: Avoid conflicts.
(If
anyone strongly feels against that, he may vote no, but I would like to
not
bikeshed that in this Vote thread, but leave it free for eventual actual
issues.)Now, the link to the RFC about Short Closures:
https://wiki.php.net/rfc/short_closures
or straight ahead to the vote:
https://wiki.php.net/rfc/short_closures#voteThanks,
Bob
I'd really like to understand what you're trying to say there Dmitry, but
I don't get it.What is your example function trying to show ?
As it mentions in the RFC, vars in short closure are by-value, so I can't
see what side effects you might be thinking of ?
It's clear to me that foo() will return NULL, but how many warnings about
unused variable $y will we get?
Thanks. Dmitry.
Cheers
JoeI'm against the magic - "automatically use () all of the (compiled)
variables".
I'm also against compound short closures with curly brackets.
in my opinion they opens too many ambiguous questions.function foo() {
(($x) ~> {$y = 3; return $y + $x;})(5);
return $y;
}also think about nested closures and use of variables from not direct
enclosure.I'm not sure if we need all "functional programming" features in PHP, but
if we introduce them, lets do it consistently with the existing language.
I think, this proposal can't be approved without support for type hinting.Thanks. Dmitry.
Hey,
Thanks for all your feedback in the discussion thread!
So, before I start the vote, just two quick notes:
I've added two notes about the statement syntax and the single variable
use.
Though a few people complained, I'm not switching to the ==> operator,
as
I noticed many people expected typehints to work (they don't due to
parser
limitations) when they compared to Hack's short Closures. It also
allows us
to differ syntax-wise [e.g. for typehints] from Hack without causing any
confusion later. Which should be the smartest choice: Avoid conflicts.
(If
anyone strongly feels against that, he may vote no, but I would like to
not
bikeshed that in this Vote thread, but leave it free for eventual actual
issues.)Now, the link to the RFC about Short Closures:
https://wiki.php.net/rfc/short_closures
or straight ahead to the vote:
https://wiki.php.net/rfc/short_closures#voteThanks,
Bob
Am 22.09.2015 um 17:36 schrieb Dmitry Stogov dmitry@zend.com:
I'd really like to understand what you're trying to say there Dmitry, but
I don't get it.What is your example function trying to show ?
As it mentions in the RFC, vars in short closure are by-value, so I can't
see what side effects you might be thinking of ?It's clear to me that foo() will return NULL, but how many warnings about
unused variable $y will we get?Thanks. Dmitry.
Cheers
JoeI'm against the magic - "automatically use () all of the (compiled)
variables".
I'm also against compound short closures with curly brackets.
in my opinion they opens too many ambiguous questions.function foo() {
(($x) ~> {$y = 3; return $y + $x;})(5);
return $y;
}also think about nested closures and use of variables from not direct
enclosure.I'm not sure if we need all "functional programming" features in PHP, but
if we introduce them, lets do it consistently with the existing language.
I think, this proposal can't be approved without support for type hinting.Thanks. Dmitry.
Hey,
Thanks for all your feedback in the discussion thread!
So, before I start the vote, just two quick notes:
I've added two notes about the statement syntax and the single variable
use.
Though a few people complained, I'm not switching to the ==> operator,
as
I noticed many people expected typehints to work (they don't due to
parser
limitations) when they compared to Hack's short Closures. It also
allows us
to differ syntax-wise [e.g. for typehints] from Hack without causing any
confusion later. Which should be the smartest choice: Avoid conflicts.
(If
anyone strongly feels against that, he may vote no, but I would like to
not
bikeshed that in this Vote thread, but leave it free for eventual actual
issues.)Now, the link to the RFC about Short Closures:
https://wiki.php.net/rfc/short_closures
or straight ahead to the vote:
https://wiki.php.net/rfc/short_closures#voteThanks,
Bob
Notice: Undefined variable: y in php shell code on line 3
It just yields exactly one notice about the inexistent $y (as it obviously does not leak through the scope): by-value binding.
I'm not sure what your issue here is?
Bob
Am 22.09.2015 um 17:36 schrieb Dmitry Stogov dmitry@zend.com:
On Tue, Sep 22, 2015 at 4:54 PM, Joe Watkins pthreads@pthreads.org
wrote:I'd really like to understand what you're trying to say there Dmitry,
but
I don't get it.What is your example function trying to show ?
As it mentions in the RFC, vars in short closure are by-value, so I
can't
see what side effects you might be thinking of ?It's clear to me that foo() will return NULL, but how many warnings about
unused variable $y will we get?Thanks. Dmitry.
Cheers
JoeI'm against the magic - "automatically use () all of the (compiled)
variables".
I'm also against compound short closures with curly brackets.
in my opinion they opens too many ambiguous questions.function foo() {
(($x) ~> {$y = 3; return $y + $x;})(5);
return $y;
}also think about nested closures and use of variables from not direct
enclosure.I'm not sure if we need all "functional programming" features in PHP,
but
if we introduce them, lets do it consistently with the existing
language.
I think, this proposal can't be approved without support for type
hinting.Thanks. Dmitry.
On Tue, Sep 22, 2015 at 4:59 AM, Bob Weinand bobwei9@hotmail.com
wrote:Hey,
Thanks for all your feedback in the discussion thread!
So, before I start the vote, just two quick notes:
I've added two notes about the statement syntax and the single
variable
use.
Though a few people complained, I'm not switching to the ==> operator,
as
I noticed many people expected typehints to work (they don't due to
parser
limitations) when they compared to Hack's short Closures. It also
allows us
to differ syntax-wise [e.g. for typehints] from Hack without causing
any
confusion later. Which should be the smartest choice: Avoid conflicts.
(If
anyone strongly feels against that, he may vote no, but I would like
to
not
bikeshed that in this Vote thread, but leave it free for eventual
actual
issues.)Now, the link to the RFC about Short Closures:
https://wiki.php.net/rfc/short_closures
or straight ahead to the vote:
https://wiki.php.net/rfc/short_closures#voteThanks,
BobNotice: Undefined variable: y in php shell code on line 3
It just yields exactly one notice about the inexistent $y (as it obviously
does not leak through the scope): by-value binding.I'm not sure what your issue here is?
The current PHP version emits two warning on similar constructs, and this
is explainable because we explicitly "use" $y.
$ sapi/cli/php -r 'function foo(){(function($x) use ($y){$y=3; return
$y+$x;})(5);return $y;} var_dump(foo());'
PHP Notice: Undefined variable: y in Command line code on line 1
PHP Notice: Undefined variable: y in Command line code on line 1
NULL
Thanks. Dmitry.
Bob
Dmitry,
Am 22.09.2015 um 17:36 schrieb Dmitry Stogov dmitry@zend.com:
On Tue, Sep 22, 2015 at 4:54 PM, Joe Watkins pthreads@pthreads.org
wrote:I'd really like to understand what you're trying to say there Dmitry,
but
I don't get it.What is your example function trying to show ?
As it mentions in the RFC, vars in short closure are by-value, so I
can't
see what side effects you might be thinking of ?It's clear to me that foo() will return NULL, but how many warnings about
unused variable $y will we get?Thanks. Dmitry.
Cheers
JoeI'm against the magic - "automatically use () all of the (compiled)
variables".
I'm also against compound short closures with curly brackets.
in my opinion they opens too many ambiguous questions.function foo() {
(($x) ~> {$y = 3; return $y + $x;})(5);
return $y;
}also think about nested closures and use of variables from not direct
enclosure.I'm not sure if we need all "functional programming" features in PHP,
but
if we introduce them, lets do it consistently with the existing
language.
I think, this proposal can't be approved without support for type
hinting.Thanks. Dmitry.
On Tue, Sep 22, 2015 at 4:59 AM, Bob Weinand bobwei9@hotmail.com
wrote:Hey,
Thanks for all your feedback in the discussion thread!
So, before I start the vote, just two quick notes:
I've added two notes about the statement syntax and the single
variable
use.
Though a few people complained, I'm not switching to the ==> operator,
as
I noticed many people expected typehints to work (they don't due to
parser
limitations) when they compared to Hack's short Closures. It also
allows us
to differ syntax-wise [e.g. for typehints] from Hack without causing
any
confusion later. Which should be the smartest choice: Avoid conflicts.
(If
anyone strongly feels against that, he may vote no, but I would like
to
not
bikeshed that in this Vote thread, but leave it free for eventual
actual
issues.)Now, the link to the RFC about Short Closures:
https://wiki.php.net/rfc/short_closures
or straight ahead to the vote:
https://wiki.php.net/rfc/short_closures#voteThanks,
BobNotice: Undefined variable: y in php shell code on line 3
It just yields exactly one notice about the inexistent $y (as it obviously
does not leak through the scope): by-value binding.I'm not sure what your issue here is?
The current PHP version emits two warning on similar constructs, and this
is explainable because we explicitly "use" $y.$ sapi/cli/php -r 'function foo(){(function($x) use ($y){$y=3; return
$y+$x;})(5);return $y;} var_dump(foo());'
PHP Notice: Undefined variable: y in Command line code on line 1PHP Notice: Undefined variable: y in Command line code on line 1
NULL
There's an important distinction here. The explicit use($y)
triggers
a notice because you said to use an undefined variable.
function foo() {
(($x) ~> {$y = 3; return $y + $x;})(5);
return $y;
}
In this case, there's no practical binding of $y
at all. The $y
in
the scope of the closure is never actually read from before it is
assigned to. Meaning the variable doesn't need to exist prior to that
assignment, meaning that it doesn't have to be bound (used), and as
such shouldn't throw a notice.
This becomes a ton easier if we ever move to an explicit CFG+SSA
compile step. Then, we can see which variables dominate the closure to
see what needs to be bound vs what doesn't. In this example, converted
to SSA, you'd see:
function foo() {
$y1 = 12;
(($x1) ~> {$y2 = 3; return $y2 + $x1;})(5);
return $y1;
}
Hence you can see that $y2
is truly an independent variable, and
hence $y1
never needs to be bound (and hence no notice).
So your case of explicitly using $y
isn't actually what's happening
with the closure (at least with respect to userland behavior). Hence
why the lack of notice exists.
My $0.02 at least,
Anthony
On Tue, Sep 22, 2015 at 9:20 PM, Anthony Ferrara ircmaxell@gmail.com
wrote:
Dmitry,
On Tue, Sep 22, 2015 at 7:01 PM, Bob Weinand bobwei9@hotmail.com
wrote:Am 22.09.2015 um 17:36 schrieb Dmitry Stogov dmitry@zend.com:
On Tue, Sep 22, 2015 at 4:54 PM, Joe Watkins pthreads@pthreads.org
wrote:I'd really like to understand what you're trying to say there Dmitry,
but
I don't get it.What is your example function trying to show ?
As it mentions in the RFC, vars in short closure are by-value, so I
can't
see what side effects you might be thinking of ?It's clear to me that foo() will return NULL, but how many warnings
about
unused variable $y will we get?Thanks. Dmitry.
Cheers
JoeOn Tue, Sep 22, 2015 at 9:25 AM, Dmitry Stogov dmitry@zend.com
wrote:I'm against the magic - "automatically use () all of the (compiled)
variables".
I'm also against compound short closures with curly brackets.
in my opinion they opens too many ambiguous questions.function foo() {
(($x) ~> {$y = 3; return $y + $x;})(5);
return $y;
}also think about nested closures and use of variables from not
direct
enclosure.I'm not sure if we need all "functional programming" features in
PHP,
but
if we introduce them, lets do it consistently with the existing
language.
I think, this proposal can't be approved without support for type
hinting.Thanks. Dmitry.
On Tue, Sep 22, 2015 at 4:59 AM, Bob Weinand bobwei9@hotmail.com
wrote:Hey,
Thanks for all your feedback in the discussion thread!
So, before I start the vote, just two quick notes:
I've added two notes about the statement syntax and the single
variable
use.
Though a few people complained, I'm not switching to the ==>
operator,
as
I noticed many people expected typehints to work (they don't due to
parser
limitations) when they compared to Hack's short Closures. It also
allows us
to differ syntax-wise [e.g. for typehints] from Hack without
causing
any
confusion later. Which should be the smartest choice: Avoid
conflicts.
(If
anyone strongly feels against that, he may vote no, but I would
like
to
not
bikeshed that in this Vote thread, but leave it free for eventual
actual
issues.)Now, the link to the RFC about Short Closures:
https://wiki.php.net/rfc/short_closures
or straight ahead to the vote:
https://wiki.php.net/rfc/short_closures#voteThanks,
BobNotice: Undefined variable: y in php shell code on line 3
It just yields exactly one notice about the inexistent $y (as it
obviously
does not leak through the scope): by-value binding.I'm not sure what your issue here is?
The current PHP version emits two warning on similar constructs, and this
is explainable because we explicitly "use" $y.$ sapi/cli/php -r 'function foo(){(function($x) use ($y){$y=3; return
$y+$x;})(5);return $y;} var_dump(foo());'
PHP Notice: Undefined variable: y in Command line code on line 1PHP Notice: Undefined variable: y in Command line code on line 1
NULL
There's an important distinction here. The explicit
use($y)
triggers
a notice because you said to use an undefined variable.function foo() {
(($x) ~> {$y = 3; return $y + $x;})(5);
return $y;
}In this case, there's no practical binding of
$y
at all. The$y
in
the scope of the closure is never actually read from before it is
assigned to. Meaning the variable doesn't need to exist prior to that
assignment, meaning that it doesn't have to be bound (used), and as
such shouldn't throw a notice.
This is not the way like PHP works and the proposed patch didn't change
this.
It produced warning on "implicit" use.
Now Bob seems to fixed this by hiding the warning.
This becomes a ton easier if we ever move to an explicit CFG+SSA
compile step. Then, we can see which variables dominate the closure to
see what needs to be bound vs what doesn't. In this example, converted
to SSA, you'd see:function foo() {
$y1 = 12;
(($x1) ~> {$y2 = 3; return $y2 + $x1;})(5);
return $y1;
}Hence you can see that
$y2
is truly an independent variable, and
hence$y1
never needs to be bound (and hence no notice).So your case of explicitly using
$y
isn't actually what's happening
with the closure (at least with respect to userland behavior). Hence
why the lack of notice exists.My $0.02 at least,
This is interesting, and I also thought about this.
But this is going to be different language with different rules.
Also, this approach can't handle all possible cases in dynamic languages,
where we can't say if variable is used or assigned first.
function foo() {
$y = 1;
$f = ($x) ~> {
for ($i = 0; $i < 2; $i++) {
if ($x) {
$y = 5;
} else {
echo $y
}
};
$f(0);
$f(1);
}
Your approach won't be able to determine if $y in short closure is local
variable or from function foo().
Anyway, this is not related to Bob's proposal.
Thanks. Dmitry.
Anthony
Dmitry,
On Tue, Sep 22, 2015 at 9:20 PM, Anthony Ferrara ircmaxell@gmail.com
wrote:Dmitry,
On Tue, Sep 22, 2015 at 7:01 PM, Bob Weinand bobwei9@hotmail.com
wrote:Am 22.09.2015 um 17:36 schrieb Dmitry Stogov dmitry@zend.com:
On Tue, Sep 22, 2015 at 4:54 PM, Joe Watkins pthreads@pthreads.org
wrote:I'd really like to understand what you're trying to say there
Dmitry,
but
I don't get it.What is your example function trying to show ?
As it mentions in the RFC, vars in short closure are by-value, so I
can't
see what side effects you might be thinking of ?It's clear to me that foo() will return NULL, but how many warnings
about
unused variable $y will we get?Thanks. Dmitry.
Cheers
JoeOn Tue, Sep 22, 2015 at 9:25 AM, Dmitry Stogov dmitry@zend.com
wrote:I'm against the magic - "automatically use () all of the (compiled)
variables".
I'm also against compound short closures with curly brackets.
in my opinion they opens too many ambiguous questions.function foo() {
(($x) ~> {$y = 3; return $y + $x;})(5);
return $y;
}also think about nested closures and use of variables from not
direct
enclosure.I'm not sure if we need all "functional programming" features in
PHP,
but
if we introduce them, lets do it consistently with the existing
language.
I think, this proposal can't be approved without support for type
hinting.Thanks. Dmitry.
On Tue, Sep 22, 2015 at 4:59 AM, Bob Weinand bobwei9@hotmail.com
wrote:Hey,
Thanks for all your feedback in the discussion thread!
So, before I start the vote, just two quick notes:
I've added two notes about the statement syntax and the single
variable
use.
Though a few people complained, I'm not switching to the ==>
operator,
as
I noticed many people expected typehints to work (they don't due
to
parser
limitations) when they compared to Hack's short Closures. It also
allows us
to differ syntax-wise [e.g. for typehints] from Hack without
causing
any
confusion later. Which should be the smartest choice: Avoid
conflicts.
(If
anyone strongly feels against that, he may vote no, but I would
like
to
not
bikeshed that in this Vote thread, but leave it free for eventual
actual
issues.)Now, the link to the RFC about Short Closures:
https://wiki.php.net/rfc/short_closures
or straight ahead to the vote:
https://wiki.php.net/rfc/short_closures#voteThanks,
BobNotice: Undefined variable: y in php shell code on line 3
It just yields exactly one notice about the inexistent $y (as it
obviously
does not leak through the scope): by-value binding.I'm not sure what your issue here is?
The current PHP version emits two warning on similar constructs, and
this
is explainable because we explicitly "use" $y.$ sapi/cli/php -r 'function foo(){(function($x) use ($y){$y=3; return
$y+$x;})(5);return $y;} var_dump(foo());'
PHP Notice: Undefined variable: y in Command line code on line 1PHP Notice: Undefined variable: y in Command line code on line 1
NULL
There's an important distinction here. The explicit
use($y)
triggers
a notice because you said to use an undefined variable.function foo() {
(($x) ~> {$y = 3; return $y + $x;})(5);
return $y;
}In this case, there's no practical binding of
$y
at all. The$y
in
the scope of the closure is never actually read from before it is
assigned to. Meaning the variable doesn't need to exist prior to that
assignment, meaning that it doesn't have to be bound (used), and as
such shouldn't throw a notice.This is not the way like PHP works and the proposed patch didn't change
this.
It produced warning on "implicit" use.
Now Bob seems to fixed this by hiding the warning.This becomes a ton easier if we ever move to an explicit CFG+SSA
compile step. Then, we can see which variables dominate the closure to
see what needs to be bound vs what doesn't. In this example, converted
to SSA, you'd see:function foo() {
$y1 = 12;
(($x1) ~> {$y2 = 3; return $y2 + $x1;})(5);
return $y1;
}Hence you can see that
$y2
is truly an independent variable, and
hence$y1
never needs to be bound (and hence no notice).So your case of explicitly using
$y
isn't actually what's happening
with the closure (at least with respect to userland behavior). Hence
why the lack of notice exists.My $0.02 at least,
This is interesting, and I also thought about this.
But this is going to be different language with different rules.
Also, this approach can't handle all possible cases in dynamic languages,
where we can't say if variable is used or assigned first.function foo() {
$y = 1;
$f = ($x) ~> {
for ($i = 0; $i < 2; $i++) {
if ($x) {
$y = 5;
} else {
echo $y
}
};
$f(0);
$f(1);
}Your approach won't be able to determine if $y in short closure is local
variable or from function foo().
Anyway, this is not related to Bob's proposal.
Yes it can. Because the usages of $y
are not fully dominated by an
assignment, there is at least one path from $y = 1
to echo $y
that
exists (this is trivial to prove). Hence the binding would need to
happen (no matter if that path was chosen by the actual execution
path).
Variable-variables would need to be taken into account, but that would
be easy to solve by saying if we see a Var-Var usage, bind everything
unless we can prove the variable is dominated inside the lambda.
And this is related to Bob's proposal in a way. Right now, he has to
bind every symbol that exists in the closure using a non-notice read
(if it exists in the parent, bind, otherwise don't notice). The point
I was making is that if we modify our compiler it can get even
smarter, reducing the cases where we over-bind (and thereby making it
more efficient). Considering that some people are concerned around the
performance implications of the binding, possible solutions to that
problem do exist and could be implemented.
Anthony
On Wed, Sep 23, 2015 at 12:00 AM, Anthony Ferrara ircmaxell@gmail.com
wrote:
Dmitry,
On Tue, Sep 22, 2015 at 9:20 PM, Anthony Ferrara ircmaxell@gmail.com
wrote:Dmitry,
On Tue, Sep 22, 2015 at 7:01 PM, Bob Weinand bobwei9@hotmail.com
wrote:Am 22.09.2015 um 17:36 schrieb Dmitry Stogov dmitry@zend.com:
On Tue, Sep 22, 2015 at 4:54 PM, Joe Watkins <
pthreads@pthreads.org>
wrote:I'd really like to understand what you're trying to say there
Dmitry,
but
I don't get it.What is your example function trying to show ?
As it mentions in the RFC, vars in short closure are by-value, so
I
can't
see what side effects you might be thinking of ?It's clear to me that foo() will return NULL, but how many warnings
about
unused variable $y will we get?Thanks. Dmitry.
Cheers
JoeOn Tue, Sep 22, 2015 at 9:25 AM, Dmitry Stogov dmitry@zend.com
wrote:I'm against the magic - "automatically use () all of the
(compiled)
variables".
I'm also against compound short closures with curly brackets.
in my opinion they opens too many ambiguous questions.function foo() {
(($x) ~> {$y = 3; return $y + $x;})(5);
return $y;
}also think about nested closures and use of variables from not
direct
enclosure.I'm not sure if we need all "functional programming" features in
PHP,
but
if we introduce them, lets do it consistently with the existing
language.
I think, this proposal can't be approved without support for type
hinting.Thanks. Dmitry.
On Tue, Sep 22, 2015 at 4:59 AM, Bob Weinand <
bobwei9@hotmail.com>
wrote:Hey,
Thanks for all your feedback in the discussion thread!
So, before I start the vote, just two quick notes:
I've added two notes about the statement syntax and the single
variable
use.
Though a few people complained, I'm not switching to the ==>
operator,
as
I noticed many people expected typehints to work (they don't due
to
parser
limitations) when they compared to Hack's short Closures. It
also
allows us
to differ syntax-wise [e.g. for typehints] from Hack without
causing
any
confusion later. Which should be the smartest choice: Avoid
conflicts.
(If
anyone strongly feels against that, he may vote no, but I would
like
to
not
bikeshed that in this Vote thread, but leave it free for
eventual
actual
issues.)Now, the link to the RFC about Short Closures:
https://wiki.php.net/rfc/short_closures
or straight ahead to the vote:
https://wiki.php.net/rfc/short_closures#voteThanks,
BobNotice: Undefined variable: y in php shell code on line 3
It just yields exactly one notice about the inexistent $y (as it
obviously
does not leak through the scope): by-value binding.I'm not sure what your issue here is?
The current PHP version emits two warning on similar constructs, and
this
is explainable because we explicitly "use" $y.$ sapi/cli/php -r 'function foo(){(function($x) use ($y){$y=3; return
$y+$x;})(5);return $y;} var_dump(foo());'
PHP Notice: Undefined variable: y in Command line code on line 1PHP Notice: Undefined variable: y in Command line code on line 1
NULL
There's an important distinction here. The explicit
use($y)
triggers
a notice because you said to use an undefined variable.function foo() {
(($x) ~> {$y = 3; return $y + $x;})(5);
return $y;
}In this case, there's no practical binding of
$y
at all. The$y
in
the scope of the closure is never actually read from before it is
assigned to. Meaning the variable doesn't need to exist prior to that
assignment, meaning that it doesn't have to be bound (used), and as
such shouldn't throw a notice.This is not the way like PHP works and the proposed patch didn't change
this.
It produced warning on "implicit" use.
Now Bob seems to fixed this by hiding the warning.This becomes a ton easier if we ever move to an explicit CFG+SSA
compile step. Then, we can see which variables dominate the closure to
see what needs to be bound vs what doesn't. In this example, converted
to SSA, you'd see:function foo() {
$y1 = 12;
(($x1) ~> {$y2 = 3; return $y2 + $x1;})(5);
return $y1;
}Hence you can see that
$y2
is truly an independent variable, and
hence$y1
never needs to be bound (and hence no notice).So your case of explicitly using
$y
isn't actually what's happening
with the closure (at least with respect to userland behavior). Hence
why the lack of notice exists.My $0.02 at least,
This is interesting, and I also thought about this.
But this is going to be different language with different rules.
Also, this approach can't handle all possible cases in dynamic languages,
where we can't say if variable is used or assigned first.function foo() {
$y = 1;
$f = ($x) ~> {
for ($i = 0; $i < 2; $i++) {
if ($x) {
$y = 5;
} else {
echo $y
}
};
$f(0);
$f(1);
}Your approach won't be able to determine if $y in short closure is local
variable or from function foo().
Anyway, this is not related to Bob's proposal.Yes it can. Because the usages of
$y
are not fully dominated by an
assignment, there is at least one path from$y = 1
toecho $y
that
exists (this is trivial to prove). Hence the binding would need to
happen (no matter if that path was chosen by the actual execution
path).
So if we have at least one path that assumes use before local assignment we
will use variable from the upper context.
This should work.
What if upper function doesn't have such variable? should it be created or
should we use local instead?
What if the upper context is global and at compile-time we don't know if
used variable exists or not?
I think, we may collect all variables of lambda that may be used before
initialized at compile-time.
At runtime we may check if upper syntax context (or even contexts) define
required vars and bind them.
This probably may work for binding by value. Use by reference will still
require explicit definition.
I don't think we can implement this in PHP (big conceptual change).
Variable-variables would need to be taken into account, but that would
be easy to solve by saying if we see a Var-Var usage, bind everything
unless we can prove the variable is dominated inside the lambda.
var-var, eval(), references and aliases make huge troubles for compile-time
decisions :(
And this is related to Bob's proposal in a way. Right now, he has to
bind every symbol that exists in the closure using a non-notice read
(if it exists in the parent, bind, otherwise don't notice). The point
I was making is that if we modify our compiler it can get even
smarter, reducing the cases where we over-bind (and thereby making it
more efficient). Considering that some people are concerned around the
performance implications of the binding, possible solutions to that
problem do exist and could be implemented.
In general, this is possible, but SSA construction is much more difficult
than the proposed by Bob patch.
Thanks. Dmitry.
Anthony
"Anthony Ferrara" wrote in message
news:CAAyV7nHVNGG8yOyGhTE=pKACi4GDTgrdVcS4RDXb2fLmNy4Zpg@mail.gmail.com...
Dmitry,
On Tue, Sep 22, 2015 at 9:20 PM, Anthony Ferrara ircmaxell@gmail.com
wrote:Dmitry,
On Tue, Sep 22, 2015 at 7:01 PM, Bob Weinand bobwei9@hotmail.com
wrote:Am 22.09.2015 um 17:36 schrieb Dmitry Stogov dmitry@zend.com:
On Tue, Sep 22, 2015 at 4:54 PM, Joe Watkins
pthreads@pthreads.org
wrote:I'd really like to understand what you're trying to say there
Dmitry,
but
I don't get it.What is your example function trying to show ?
As it mentions in the RFC, vars in short closure are by-value, so
I
can't
see what side effects you might be thinking of ?It's clear to me that foo() will return NULL, but how many warnings
about
unused variable $y will we get?Thanks. Dmitry.
Cheers
JoeOn Tue, Sep 22, 2015 at 9:25 AM, Dmitry Stogov dmitry@zend.com
wrote:I'm against the magic - "automatically use () all of the
(compiled)
variables".
I'm also against compound short closures with curly brackets.
in my opinion they opens too many ambiguous questions.function foo() {
(($x) ~> {$y = 3; return $y + $x;})(5);
return $y;
}also think about nested closures and use of variables from not
direct
enclosure.I'm not sure if we need all "functional programming" features in
PHP,
but
if we introduce them, lets do it consistently with the existing
language.
I think, this proposal can't be approved without support for type
hinting.Thanks. Dmitry.
On Tue, Sep 22, 2015 at 4:59 AM, Bob Weinand
bobwei9@hotmail.com
wrote:Hey,
Thanks for all your feedback in the discussion thread!
So, before I start the vote, just two quick notes:
I've added two notes about the statement syntax and the single
variable
use.
Though a few people complained, I'm not switching to the ==>
operator,
as
I noticed many people expected typehints to work (they don't due
to
parser
limitations) when they compared to Hack's short Closures. It
also
allows us
to differ syntax-wise [e.g. for typehints] from Hack without
causing
any
confusion later. Which should be the smartest choice: Avoid
conflicts.
(If
anyone strongly feels against that, he may vote no, but I would
like
to
not
bikeshed that in this Vote thread, but leave it free for
eventual
actual
issues.)Now, the link to the RFC about Short Closures:
https://wiki.php.net/rfc/short_closures
or straight ahead to the vote:
https://wiki.php.net/rfc/short_closures#voteThanks,
BobNotice: Undefined variable: y in php shell code on line 3
It just yields exactly one notice about the inexistent $y (as it
obviously
does not leak through the scope): by-value binding.I'm not sure what your issue here is?
The current PHP version emits two warning on similar constructs, and
this
is explainable because we explicitly "use" $y.$ sapi/cli/php -r 'function foo(){(function($x) use ($y){$y=3; return
$y+$x;})(5);return $y;} var_dump(foo());'
PHP Notice: Undefined variable: y in Command line code on line 1PHP Notice: Undefined variable: y in Command line code on line 1
NULL
There's an important distinction here. The explicit
use($y)
triggers
a notice because you said to use an undefined variable.function foo() {
(($x) ~> {$y = 3; return $y + $x;})(5);
return $y;
}In this case, there's no practical binding of
$y
at all. The$y
in
the scope of the closure is never actually read from before it is
assigned to. Meaning the variable doesn't need to exist prior to that
assignment, meaning that it doesn't have to be bound (used), and as
such shouldn't throw a notice.This is not the way like PHP works and the proposed patch didn't change
this.
It produced warning on "implicit" use.
Now Bob seems to fixed this by hiding the warning.This becomes a ton easier if we ever move to an explicit CFG+SSA
compile step. Then, we can see which variables dominate the closure to
see what needs to be bound vs what doesn't. In this example, converted
to SSA, you'd see:function foo() {
$y1 = 12;
(($x1) ~> {$y2 = 3; return $y2 + $x1;})(5);
return $y1;
}Hence you can see that
$y2
is truly an independent variable, and
hence$y1
never needs to be bound (and hence no notice).So your case of explicitly using
$y
isn't actually what's happening
with the closure (at least with respect to userland behavior). Hence
why the lack of notice exists.My $0.02 at least,
This is interesting, and I also thought about this.
But this is going to be different language with different rules.
Also, this approach can't handle all possible cases in dynamic languages,
where we can't say if variable is used or assigned first.function foo() {
$y = 1;
$f = ($x) ~> {
for ($i = 0; $i < 2; $i++) {
if ($x) {
$y = 5;
} else {
echo $y
}
};
$f(0);
$f(1);
}Your approach won't be able to determine if $y in short closure is local
variable or from function foo().
Anyway, this is not related to Bob's proposal.Yes it can. Because the usages of
$y
are not fully dominated by an
assignment, there is at least one path from$y = 1
toecho $y
that
exists (this is trivial to prove). Hence the binding would need to
happen (no matter if that path was chosen by the actual execution
path).Variable-variables would need to be taken into account, but that would
be easy to solve by saying if we see a Var-Var usage, bind everything
unless we can prove the variable is dominated inside the lambda.And this is related to Bob's proposal in a way. Right now, he has to
bind every symbol that exists in the closure using a non-notice read
(if it exists in the parent, bind, otherwise don't notice). The point
I was making is that if we modify our compiler it can get even
smarter, reducing the cases where we over-bind (and thereby making it
more efficient). Considering that some people are concerned around the
performance implications of the binding, possible solutions to that
problem do exist and could be implemented.Anthony
The more I read of this thread the more I think that it is a totally bad
idea. If a single line of code requires a whole page to describe what it
does, and even then there is a great deal of confusion between different
people, then I would class that line of code as "unreadable". By this I mean
that if I cannot determine within 5 seconds what a line of code does with
complete accuracy then it becomes a maintenance nightmare. The objective of
"good" programming is NOT to write code with as few keystrokes as possible,
it is, as Abelson and Sussman wrote in 1944, "Programs must be written for
people to read, and only incidentally for machines to execute". Martin
Fowler, the author of Patterns of Enterprise Application Architecture, wrote
"Any fool can write code that a computer can understand. Good programmers
write code that humans can understand. "
Please please please STOP with this nonsense about writing small amounts of
clever code and stick with writing simple but readable code. I would much
rather see 5 separate instructions on 5 separate lines than 5 instructions
squeezed into a single line. IMHO the readability of a piece of code is
directly proportional to the number of keystrokes used to write it. In other
words, less keystrokes equals less readability.
--
Tony Marston
Am 22.09.2015 um 20:05 schrieb Dmitry Stogov dmitry@zend.com:
The current PHP version emits two warning on similar constructs, and this
is explainable because we explicitly "use" $y.$ sapi/cli/php -r 'function foo(){(function($x) use ($y){$y=3; return
$y+$x;})(5);return $y;} var_dump(foo());'
PHP Notice: Undefined variable: y in Command line code on line 1PHP Notice: Undefined variable: y in Command line code on line 1
NULL
Thanks. Dmitry.
Well, yes. But that obviously needs alternate handling here as we don't have full analysis to look at whether we'd need to import or not. Hence we just are importing everything if it's used in Closure scope and defined in parent scope.
Because we obviously don't want this to emit a notice:
function foo() {
return ($x ~> {
$y = 2;
return $x + $y;
})(10);
}
Else it'd be totally impossible to define any variables...
Also, the long form sets $y to NULL
in the Closure (we just have two notices there because you return $y; too… if you remove that, you'll be left with just one notice.
Bob
Am 22.09.2015 um 20:05 schrieb Dmitry Stogov dmitry@zend.com:
The current PHP version emits two warning on similar constructs, and this
is explainable because we explicitly "use" $y.$ sapi/cli/php -r 'function foo(){(function($x) use ($y){$y=3; return
$y+$x;})(5);return $y;} var_dump(foo());'
PHP Notice: Undefined variable: y in Command line code on line 1PHP Notice: Undefined variable: y in Command line code on line 1
NULL
Thanks. Dmitry.
Well, yes. But that obviously needs alternate handling here as we don't
have full analysis to look at whether we'd need to import or not. Hence we
just are importing everything if it's used in Closure scope and defined in
parent scope.Because we obviously don't want this to emit a notice:
function foo() {
return ($x ~> {
$y = 2;
return $x + $y;
})(10);
}Else it'd be totally impossible to define any variables...
Also, the long form sets $y to
NULL
in the Closure (we just have two
notices there because you return $y; too… if you remove that, you'll be
left with just one notice.
I saw, you have fixed that warning on implicit use.
Thanks. Dmitry.
Bob
Hi,
The introduction claims:
"he current implementation of anonymous functions in PHP is quite verbose
compared to other languages. That makes using anonymous functions be more
difficult than it could be, as there is both more to type, and more
importantly the current implementation makes it hard to read (and so
maintain) code that uses anonymous functions."
I personally feel that the "verbosity" of the way PHP is doing closures at
the moment is a good thing. It is much more readable and clear what is
happening than with ~>.
I further believe that the automatic binding of variables creates a lot
less clear and maintainable code, easy to be misunderstood and prone for
mistakes.
Which to me means the Proposal is actually doing the opposite of what it
claims to improve.
hence, i voted against it.
regards,
Peter Petermann
Hi Bob,
Bob Weinand wrote:
Hey,
Thanks for all your feedback in the discussion thread!
So, before I start the vote, just two quick notes:
I've added two notes about the statement syntax and the single variable use.
Though a few people complained, I'm not switching to the ==> operator, as I noticed many people expected typehints to work (they don't due to parser limitations) when they compared to Hack's short Closures. It also allows us to differ syntax-wise [e.g. for typehints] from Hack without causing any confusion later. Which should be the smartest choice: Avoid conflicts. (If anyone strongly feels against that, he may vote no, but I would like to not bikeshed that in this Vote thread, but leave it free for eventual actual issues.)Now, the link to the RFC about Short Closures:
https://wiki.php.net/rfc/short_closures
or straight ahead to the vote:
https://wiki.php.net/rfc/short_closures#vote
I am unhappy with the ~> syntax choice. As I've mentioned before, it's
hard to type for many people, it looks too much like ->, and it's
unnecessarily different from Hack's ==>, of which this RFC would
otherwise be proposing a strict subset.
So, I am voting against.
Thanks.
--
Andrea Faulds
http://ajf.me/
I am unhappy with the ~> syntax choice. As I've mentioned before, it's
hard to type for many people, it looks too much like ->, and it's
unnecessarily different from Hack's ==>, of which this RFC would otherwise
be proposing a strict subset.So, I am voting against.
Same reason here.
Thanks,
Pierre
Changed my vote to "no" after thinking further into it:
- I don't like the usage of the tilde:
->
and~>
are too similar and
easily confused - Using
==>
would align PHP further to hacklang, which is a plus - I'm still conflicted on automatically importing all of the scope into
the closure: while it is working for functional languages, that's where
most of the headaches come from in languages such as javascript.
Marco Pivetta
I am unhappy with the ~> syntax choice. As I've mentioned before, it's
hard to type for many people, it looks too much like ->, and it's
unnecessarily different from Hack's ==>, of which this RFC would otherwise
be proposing a strict subset.So, I am voting against.
Same reason here.
Thanks,
Pierre
Hi,
As a PHP developer, I agree with the possible confusion between ->
and
~>
.
==>
is a better choice IMHO, for its similarity with Hacklang syntax, as
said previously.
Thanks.
Julien BENOIT
PHP & JS developer @GuestToGuest https://twitter.com/GuestToGuest
Paris, FR.
blog.julienbenoit.net
http://fr.linkedin.com/in/jbenoit2011
http://www.viadeo.com/profile/0021vk9j4z60jp63/
https://github.com/jbenoit2011
2015-09-24 8:39 GMT+02:00 Marco Pivetta ocramius@gmail.com:
Changed my vote to "no" after thinking further into it:
- I don't like the usage of the tilde:
->
and~>
are too similar and
easily confused- Using
==>
would align PHP further to hacklang, which is a plus- I'm still conflicted on automatically importing all of the scope into
the closure: while it is working for functional languages, that's where
most of the headaches come from in languages such as javascript.Marco Pivetta
I am unhappy with the ~> syntax choice. As I've mentioned before, it's
hard to type for many people, it looks too much like ->, and it's
unnecessarily different from Hack's ==>, of which this RFC would
otherwise
be proposing a strict subset.So, I am voting against.
Same reason here.
Thanks,
Pierre
Hi!
As a PHP developer, I agree with the possible confusion between
->
and
~>
.
==>
is a better choice IMHO, for its similarity with Hacklang syntax, as
said previously.
I'm getting a feeling the RFC could be more successful if syntax was
made a choice between ~> and ==> as a voting option.
Stas Malyshev
smalyshev@gmail.com
Hi!
As a PHP developer, I agree with the possible confusion between
->
and
~>
.
==>
is a better choice IMHO, for its similarity with Hacklang syntax,
as
said previously.I'm getting a feeling the RFC could be more successful if syntax was
made a choice between ~> and ==> as a voting option.
Yes, given we do not have issues with the use (which seems to be cleared
now)
Stas Malyshev
smalyshev@gmail.com
Den 2015-09-24 kl. 09:10, skrev Stanislav Malyshev:
Hi!
As a PHP developer, I agree with the possible confusion between
->
and
~>
.
==>
is a better choice IMHO, for its similarity with Hacklang syntax, as
said previously.
I'm getting a feeling the RFC could be more successful if syntax was
made a choice between ~> and ==> as a voting option.
How does one then address that this RFC only covers a subset of
Hacklang functionality when having the same operator?
--
//Björn Larsson
Hi!
How does one then address that this RFC only covers a subset of
Hacklang functionality when having the same operator?
Why one should address it? PHP is a different language, and we are under
no obligation to completely match functionality of any other language.
--
Stas Malyshev
smalyshev@gmail.com
How does one then address that this RFC only covers a subset of
Hacklang functionality when having the same operator?Why one should address it? PHP is a different language, and we are
under
no obligation to completely match functionality of any other language.
Well, if the only reason for selecting that operator was to match Hack, it would be odd to take its meaning in a different direction.
Other reasons have been given, though, and the functionality is similar enough, so I don't think it's a big problem myself, but I can see the logic of questioning it.
Regards,
Rowan Collins
[IMSoP]
Den 2015-09-24 kl. 20:21, skrev Stanislav Malyshev:
Hi!
How does one then address that this RFC only covers a subset of
Hacklang functionality when having the same operator?
Why one should address it? PHP is a different language, and we are under
no obligation to completely match functionality of any other language.
In principal I agree, but by using the same operator one sets an
end-user expectation that the functionality is close to the same.
Regards //Björn Larsson
Stas,
Hi!
How does one then address that this RFC only covers a subset of
Hacklang functionality when having the same operator?Why one should address it? PHP is a different language, and we are under
no obligation to completely match functionality of any other language.
Correct. We are under no obligation. But, it would be us playing
friendly neighbor and responsible community citizen if we didn't
re-use syntax in a different way. Remember, Hack isn't some arbitrary
different language, it's one that exists in the PHP ecosystem. We are
under no obligation to play nicely with them, but wouldn't it be nice
if we did anyway?
And part of that playing nice would be not re-using syntax in
different ways (that goes in both directions). Since that only will
make everyone's life more difficult.
Anthony
On Thu, Sep 24, 2015 at 12:10 AM, Stanislav Malyshev
smalyshev@gmail.com wrote:
As a PHP developer, I agree with the possible confusion between
->
and
~>
.
==>
is a better choice IMHO, for its similarity with Hacklang syntax, as
said previously.I'm getting a feeling the RFC could be more successful if syntax was
made a choice between ~> and ==> as a voting option.
Agreed. Let's leave the bike-shedding over operators to its own
topic. The binding rules are much more consequential and deserving of
discussion.
-Sara
- I'm still conflicted on automatically importing all of the scope into
the closure: while it is working for functional languages, that's where
most of the headaches come from in languages such as javascript.
Isn't this the crux of some decisions? Once one adopts compiling as an
essential step a number of the rules can be changed. So is PHP heading
down the path of a compiled language even if that is hidden in some
automatic cache or is it still mainly an interpreted script? Lots of
things are easier if you apply optimization in the compile stage but
that then blocks many of the dynamic actions which PHP IS so good at.
The sort of thing that allows thousands of pages of content to be stored
in a database without some of the straight jacket that some people seem
to think is essential these days?
If I'd wanted a fully compiled system I'd have stayed with C/C++ all
those years ago ... as I keep harping on PHPs dynamic nature is it's
strength?
--
Lester Caine - G8HFL
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk
Lester Caine wrote on 24/09/2015 08:06:
So is PHP heading
down the path of a compiled language even if that is hidden in some
automatic cache or is it still mainly an interpreted script?
PHP already is a compiled language; it just has a highly dynamic runtime
engine (which is at times a blessing, and at times a curse).
- I'm still conflicted on automatically importing all of the scope into
the closure: while it is working for functional languages, that's where
most of the headaches come from in languages such as javascript.Isn't this the crux of some decisions? Once one adopts compiling as an
essential step a number of the rules can be changed. So is PHP heading
down the path of a compiled language even if that is hidden in some
automatic cache or is it still mainly an interpreted script? Lots of
things are easier if you apply optimization in the compile stage but
that then blocks many of the dynamic actions which PHP IS so good at.
The sort of thing that allows thousands of pages of content to be stored
in a database without some of the straight jacket that some people seem
to think is essential these days?If I'd wanted a fully compiled system I'd have stayed with C/C++ all
those years ago ... as I keep harping on PHPs dynamic nature is it's
strength?
I assume you mean strongly typed, because PHP has had a compiler for about
18 years ;)
The main restriction on PHP's compiler is really that it has to be
reasonably fast, it can't afford to do all the clever and very expensive
optimizations that for example gcc does. Maybe less so today when we can
expect everyone to have an op cache, but still.
Auto-importing variables would not be expensive, or even noticeable. But it
breaks completely from PHP's model of always being explicit about taking
symbols from another scope (globals). This is a property on which PHP
differs from other languages such as JS, Ruby or Groovy, which have similar
constructs. Is it OK to introduce an exception to that only for the sake of
having (an admittedly handy) short syntax for closures?
It's one of these "you want it, but it's not good for you" predicaments. My
vote will be no, unfortunately.
- Stig
- I'm still conflicted on automatically importing all of the scope into
the closure: while it is working for functional languages, that's where
most of the headaches come from in languages such as javascript.
The automatic import IMO isn't as much an issue as in JS, because it
imports by value and not by reference as is done in JS. If you do $foo =
'bar'; in your closure and suddenly someone in the outer scope defines
$foo as well, you aren't going to overwrite that outer scope value.
Therefore the risks for interferences are reduced quite a bit.
Cheers
--
Jordi Boggiano
@seldaek - http://seld.be
Hi,
-----Original Message-----
From: Bob Weinand [mailto:bobwei9@hotmail.com]
Sent: Tuesday, September 22, 2015 4:00 AM
To: PHP internals internals@lists.php.net
Subject: [PHP-DEV] [RFC] [VOTE] Short ClosuresHey,
Thanks for all your feedback in the discussion thread!
So, before I start the vote, just two quick notes:
I've added two notes about the statement syntax and the single variable
use.
Though a few people complained, I'm not switching to the ==> operator, as
I
noticed many people expected typehints to work (they don't due to parser
limitations) when they compared to Hack's short Closures. It also allows
us to
differ syntax-wise [e.g. for typehints] from Hack without causing any
confusion
later. Which should be the smartest choice: Avoid conflicts. (If anyone
strongly
feels against that, he may vote no, but I would like to not bikeshed that
in this
Vote thread, but leave it free for eventual actual issues.)Now, the link to the RFC about Short Closures:
https://wiki.php.net/rfc/short_closures
or straight ahead to the vote:
https://wiki.php.net/rfc/short_closures#vote
To explain my "no" vote - the concerns about tilde usage and lack on type
hints support was decisive for me. Also, as in the example with short
definitions to access properties while it actually lacks on proper accessors
syntax- well, probably not the best example.
Regards
Anatol
Hi,
So, before I start the vote, just two quick notes:
I've added two notes about the statement syntax and the single variable
use.
Though a few people complained, I'm not switching to the ==> operator, as
I noticed many people expected typehints to work (they don't due to parser
limitations) when they compared to Hack's short Closures. It also allows us
to differ syntax-wise [e.g. for typehints] from Hack without causing any
confusion later. Which should be the smartest choice: Avoid conflicts. (If
anyone strongly feels against that, he may vote no, but I would like to not
bikeshed that in this Vote thread, but leave it free for eventual actual
issues.)
I voted "no" because I'm against the automatic use () and introducing a new
symbol.
An earlier short closure RFC 1 supports explicit import, and I would want
to see explicit import mandated. And rather than inventing a new symbol,
why not just re-purpose 'as' in this context?
function sumEventScores($events, $scores) {
$types = array_map($event as $event['type'], $events);
return array_reduce($types, ($sum, $type) as $sum + $scores[$type]);
}
'use' is already purposed in three places, I don't see why 'as' can't also
be in three places. Though I've not checked the engine source to see the
actual effort, so this just may be astronaut architecting.
Anyway, thanks to Bob for his hard work pulling this together and everyone
for arguing it out. That's what makes PHP great.
Sincerely,
bishop
Hi,
So, before I start the vote, just two quick notes:
I've added two notes about the statement syntax and the single variable
use.
Though a few people complained, I'm not switching to the ==> operator, as
I noticed many people expected typehints to work (they don't due to parser
limitations) when they compared to Hack's short Closures. It also allows us
to differ syntax-wise [e.g. for typehints] from Hack without causing any
confusion later. Which should be the smartest choice: Avoid conflicts. (If
anyone strongly feels against that, he may vote no, but I would like to not
bikeshed that in this Vote thread, but leave it free for eventual actual
issues.)I voted "no" because I'm against the automatic use () and introducing a new
symbol.An earlier short closure RFC 1 supports explicit import, and I would want
to see explicit import mandated. And rather than inventing a new symbol,
why not just re-purpose 'as' in this context?function sumEventScores($events, $scores) {
$types = array_map($event as $event['type'], $events);
return array_reduce($types, ($sum, $type) as $sum + $scores[$type]);
}'use' is already purposed in three places, I don't see why 'as' can't also
be in three places. Though I've not checked the engine source to see the
actual effort, so this just may be astronaut architecting.Anyway, thanks to Bob for his hard work pulling this together and everyone
for arguing it out. That's what makes PHP great.Sincerely,
bishop
Hello,
I can't grasp the "intent" behind the "as". Reading it like "parameter
$sum and parameter type as $sum + $scores[$type]" seems pretty
confusing to me.
Also, if we look at the example from RFC - with your "as" suggestion,
it would look like this:
function reduce(callable $fn) {
return $initial as $input as {
$accumulator = $initial;
foreach ($input as $value) {
$accumulator = $fn($accumulator, $value);
}
return $accumulator;
};
}
This doesn't seem like the right way to me. :(
Regards
Pavel Kouřil
Hey,
Thanks for all your feedback in the discussion thread!
So, before I start the vote, just two quick notes:
I've added two notes about the statement syntax and the single variable use.
Though a few people complained, I'm not switching to the ==> operator, as I noticed many people expected typehints to work (they don't due to parser limitations) when they compared to Hack's short Closures. It also allows us to differ syntax-wise [e.g. for typehints] from Hack without causing any confusion later. Which should be the smartest choice: Avoid conflicts. (If anyone strongly feels against that, he may vote no, but I would like to not bikeshed that in this Vote thread, but leave it free for eventual actual issues.)Now, the link to the RFC about Short Closures:
https://wiki.php.net/rfc/short_closures
or straight ahead to the vote:
https://wiki.php.net/rfc/short_closures#voteThanks,
Bob
Hello,
since the RFC doesn't look like it will pass, I have a question about
RFC process - will you be able to "fix" the RFC and submit it for vote
again with targeting PHP 7.1?
The biggest issues seem to be
- ~> operator instead of ==>
- missing type hints
- auto imports
If probably the first two would be resolved, then maybe the RFC could
get accepted? I personally don't understand the 3rd complain, since
having to use() everything would make it "not-so-short closures".
I also remember people not liking the option not to have parenthesis
with single parameter. I was thinking about this, and with the type
hints, it would be probably better anyways to have the ( ) required,
so that would be just a single use case where they wouldn't be
required - so is there a point in keeping this special use case?
Regards
Pavel Kouřil
Hi!
since the RFC doesn't look like it will pass, I have a question about
RFC process - will you be able to "fix" the RFC and submit it for vote
again with targeting PHP 7.1?
Yes, but see:
https://wiki.php.net/rfc/voting#resurrecting_rejected_proposals
So, to make another try, the RFC needs to be substantially amended or
resubmitted in 6 months.
The biggest issues seem to be
- ~> operator instead of ==>
- missing type hints
- auto imports
I would say changing these would be substantial. Just changing the
operator - not sure, maybe if it is clear that with this change vote
would pass (which currently isn't clear at all).
Stas Malyshev
smalyshev@gmail.com
Hi!
since the RFC doesn't look like it will pass, I have a question about
RFC process - will you be able to "fix" the RFC and submit it for vote
again with targeting PHP 7.1?Yes, but see:
https://wiki.php.net/rfc/voting#resurrecting_rejected_proposalsSo, to make another try, the RFC needs to be substantially amended or
resubmitted in 6 months.The biggest issues seem to be
- ~> operator instead of ==>
- missing type hints
- auto imports
I would say changing these would be substantial. Just changing the
operator - not sure, maybe if it is clear that with this change vote
would pass (which currently isn't clear at all).Stas Malyshev
smalyshev@gmail.com
Seems you are right it's not clear after all; I skimmed through all
the e-mails in this thread and found only around 5 people stating that
the ~> operator was their reason to vote "no"; while I was writing the
previous e-mail, I really thought more people stated that here; on the
other hand, we don't know why the rest of those ~30 people voted no,
so it's really hard to say.
Anyways, thanks for sending the Ressurecting rejected proposals info. :)
Regards
Pavel Kouřil
Hi,
Hi!
The biggest issues seem to be
- ~> operator instead of ==>
- missing type hints
- auto imports
Seems you are right it's not clear after all; I skimmed through all
the e-mails in this thread and found only around 5 people stating that
the ~> operator was their reason to vote "no"; while I was writing the
previous e-mail, I really thought more people stated that here; on the
other hand, we don't know why the rest of those ~30 people voted no,
so it's really hard to say.
For what it's worth: My reasons to vote no were a) the general
readability, particularly when the parentheses are missing as well as
the choice of operator and b) the lack of type declarations.
I can see the benefit of auto imports but consider it a break of
concepts (habit?) from everywhere else in PHP.
Regards,
Arne Blankerts
--
Those who do not understand Unix
are condemned to reinvent it, poorly (Henry Spencer,1987)
Den 2015-09-26 kl. 09:18, skrev Pavel Kouřil:
Hey,
Thanks for all your feedback in the discussion thread!
So, before I start the vote, just two quick notes:
I've added two notes about the statement syntax and the single variable use.
Though a few people complained, I'm not switching to the ==> operator, as I noticed many people expected typehints to work (they don't due to parser limitations) when they compared to Hack's short Closures. It also allows us to differ syntax-wise [e.g. for typehints] from Hack without causing any confusion later. Which should be the smartest choice: Avoid conflicts. (If anyone strongly feels against that, he may vote no, but I would like to not bikeshed that in this Vote thread, but leave it free for eventual actual issues.)Now, the link to the RFC about Short Closures:
https://wiki.php.net/rfc/short_closures
or straight ahead to the vote:
https://wiki.php.net/rfc/short_closures#voteThanks,
BobHello,
since the RFC doesn't look like it will pass, I have a question about
RFC process - will you be able to "fix" the RFC and submit it for vote
again with targeting PHP 7.1?The biggest issues seem to be
- ~> operator instead of ==>
- missing type hints
- auto imports
If probably the first two would be resolved, then maybe the RFC could
get accepted? I personally don't understand the 3rd complain, since
having to use() everything would make it "not-so-short closures".I also remember people not liking the option not to have parenthesis
with single parameter. I was thinking about this, and with the type
hints, it would be probably better anyways to have the ( ) required,
so that would be just a single use case where they wouldn't be
required - so is there a point in keeping this special use case?Regards
Pavel Kouřil
A good strategy. Suspect that fixing type hints & reach consensus
on auto import or not is enough to make it pass, maybe also
parenthesis.
I don't think ~> or ==> is cruical but then I personally favour ~>
because I find it more distinct, not confusing it with => or <=>.
Also having ==> might lead the thought that functionality is like
== vs ===. Hm... or if someday in the future comparison operator
without type juggling is needed.
Regards //Björn Larsson
On Mon, Sep 28, 2015 at 2:29 PM, Björn Larsson
bjorn.x.larsson@telia.com wrote:
... or if someday in the future comparison operator
without type juggling is needed.
You just blew my mind. Trying to imagine where strict
greater-than-or-equal would be used, and more to the point: What you'd
make strict grater than look like. >>>
? Nope, you'd have heredoc
conflict on strict-less than <<<
.
-Sara
Den 2015-10-02 kl. 18:50, skrev Sara Golemon:
On Mon, Sep 28, 2015 at 2:29 PM, Björn Larsson
bjorn.x.larsson@telia.com wrote:... or if someday in the future comparison operator
without type juggling is needed.You just blew my mind. Trying to imagine where strict
greater-than-or-equal would be used, and more to the point: What you'd
make strict grater than look like.>>>
? Nope, you'd have heredoc
conflict on strict-less than<<<
.-Sara
Glad I managed to do that :) What I had in mind was strings
compared with int, like: "2 horses" > 1. And yes, syntax is
a bit blocked...
Leaves the options, >==, <== or >>=, <<=. But I don't like the
last ones. One might also consider extending the spaceship
operator to <==> for strict comparison.
I don't have a strong opinion on relevant use cases for this, so
I leave it at that.
/Cheers //Björn/
PS Think I blew my own mind a little too ;)
On Fri, Oct 2, 2015 at 12:33 PM, Björn Larsson
bjorn.x.larsson@telia.com wrote:
Leaves the options, >==, <== or >>=, <<=. But I don't like the
last ones. One might also consider extending the spaceship
operator to <==> for strict comparison.
Shift-left assign: >>=
Shift-right assign: <<=
So no on both of those.
But >==, <==, and <==> seem reasonableish, if one went that direction...
-Sara