Hi:
T_LIST
is not allowed to used with foreach before.
and then there comes a freature request: #10203 allow
foreach($array as list($a,$b)
I have work on it, and now submit patch to internal.
I have set up a rfc page in wiki.php.net:
https://wiki.php.net/rfc/foreachlist
do you think this can be involved in PHP-5.4.0?
ps: sorry for my poor english. and this was a re-post with title changed.
thanks
--
Xinchen Hui Laruence
http://www.laruence.com
2011/7/6 Xinchen Hui laruence@gmail.com:
Hi:
T_LIST
is not allowed to used with foreach before.and then there comes a freature request: #10203 allow
foreach($array as list($a,$b)
Ironically enough you managed to miss the last closing ), enforcing
the point of this not being a natural syntax.
Furthermore, without reading the RFC, is this the same as
foreach($array as $a => $b) {}
or
foreach($array as $e) {
list($a, $b) = $e;
}
or.. ?
that really doesn't look like something PHP should support imo.
-Hannes
Hi,
2011/7/6 Xinchen Hui laruence@gmail.com:
T_LIST
is not allowed to used with foreach before.and then there comes a freature request: #10203 allow
foreach($array as list($a,$b)Ironically enough you managed to miss the last closing ), enforcing
the point of this not being a natural syntax.Furthermore, without reading the RFC, is this the same as
foreach($array as $a => $b) {}
No, there $a would be the key. Intention would be, as I read the RFC,
that this could be an arbitrary list.
or
foreach($array as $e) {
list($a, $b) = $e;
}
Yes, I understood if like that. Just a short notation.
or.. ?
that really doesn't look like something PHP should support imo.
Don't see too many bad things about the idea ...
Regards,
Stefan
Hi:
first of all, I am a guy whose english is poor, sorry for making you confuse.
the feature request is here: https://bugs.php.net/bug.php?id=10203
and I think this can make php code more flexible, and more making sense.
example:
foreach (array(
array(3, array(1, 2)),
array(7, array(3, 4)),
) as list($sum, list($op1, $op2))) {
printf("%d + %d = %d\n", $op1, $op2, $sum);
}
output:
1 + 2 = 3
3 + 4 = 7
plz read the RFC for more details.
thanks
2011/7/6 Stefan Neufeind neufeind@php.net:
Hi,
2011/7/6 Xinchen Hui laruence@gmail.com:
T_LIST
is not allowed to used with foreach before.and then there comes a freature request: #10203 allow
foreach($array as list($a,$b)Ironically enough you managed to miss the last closing ), enforcing
the point of this not being a natural syntax.Furthermore, without reading the RFC, is this the same as
foreach($array as $a => $b) {}No, there $a would be the key. Intention would be, as I read the RFC,
that this could be an arbitrary list.or
foreach($array as $e) {
list($a, $b) = $e;
}Yes, I understood if like that. Just a short notation.
or.. ?
that really doesn't look like something PHP should support imo.
Don't see too many bad things about the idea ...
Regards,
Stefan--
--
惠新宸 laruence
Senior PHP Engineer
http://www.laruence.com
+1 for adding this.
I don't know enough C to review the patches. The first one looks fine though
at first glance (apart from some CS *nits probably, like duplicate
parenthesis and usage of if {} else { if {} else {}} instead of if {} elseif
{} else {}).
Your second patch (the one for adding the silence operator) though seems
strange. For example you are calling zend_do_begin_silence regardless of
whether '@' was used, don't you?
Hi:
first of all, I am a guy whose english is poor, sorry for making you
confuse.the feature request is here: https://bugs.php.net/bug.php?id=10203
and I think this can make php code more flexible, and more making sense.
example:
foreach (array(
array(3, array(1, 2)),
array(7, array(3, 4)),
) as list($sum, list($op1, $op2))) {
printf("%d + %d = %d\n", $op1, $op2, $sum);
}output:
1 + 2 = 3
3 + 4 = 7plz read the RFC for more details.
thanks
2011/7/6 Stefan Neufeind neufeind@php.net:
Hi,
2011/7/6 Xinchen Hui laruence@gmail.com:
T_LIST
is not allowed to used with foreach before.and then there comes a freature request: #10203 allow
foreach($array as list($a,$b)Ironically enough you managed to miss the last closing ), enforcing
the point of this not being a natural syntax.Furthermore, without reading the RFC, is this the same as
foreach($array as $a => $b) {}No, there $a would be the key. Intention would be, as I read the RFC,
that this could be an arbitrary list.or
foreach($array as $e) {
list($a, $b) = $e;
}Yes, I understood if like that. Just a short notation.
or.. ?
that really doesn't look like something PHP should support imo.
Don't see too many bad things about the idea ...
Regards,
Stefan--
--
惠新宸 laruence
Senior PHP Engineer
http://www.laruence.com