FAQ
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

Search Discussions

  • Hannes Magnusson at Jul 6, 2011 at 1:06 pm

    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
  • Stefan Neufeind at Jul 6, 2011 at 1:15 pm
    Hi,
    On 07/06/2011 03:06 PM, Hannes Magnusson wrote:
    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
  • Xinchen Hui at Jul 6, 2011 at 1:33 pm
    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,
    On 07/06/2011 03:06 PM, Hannes Magnusson wrote:
    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

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


    --
    惠新宸        laruence
    Senior PHP Engineer
    http://www.laruence.com
  • Nikita Popov at Jul 7, 2011 at 3:50 pm
    +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?

    On Wed, Jul 6, 2011 at 3:33 PM, Xinchen Hui wrote:

    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,
    On 07/06/2011 03:06 PM, Hannes Magnusson wrote:
    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

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


    --
    惠新宸 laruence
    Senior PHP Engineer
    http://www.laruence.com

    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: http://www.php.net/unsub.php
  • Xinchen Hui at Jul 7, 2011 at 3:50 pm
    Hi:

    thanks very much for this, that second patch is a wrong one, updated ..

    thanks

    2011/7/7 Nikita Popov <nikita.ppv@googlemail.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?

    On Wed, Jul 6, 2011 at 3:33 PM, Xinchen Hui wrote:

    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,
    On 07/06/2011 03:06 PM, Hannes Magnusson wrote:
    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

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


    --
    惠新宸        laruence
    Senior PHP Engineer
    http://www.laruence.com

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


    --
    惠新宸        laruence
    Senior PHP Engineer
    http://www.laruence.com
  • Xinchen Hui at Aug 23, 2011 at 3:44 am
    Hi:
    I found this feature was decided to do in PHP 5.3 TODO list :
    http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/TODO?revision=242949&view=markup

    so I was wondering does this previous decision still shoudl be
    think as valid? hehe

    thanks

    2011/7/7 Xinchen Hui <laruence@gmail.com>:
    Hi:

    thanks very much for this, that second patch is a wrong one,  updated ..

    thanks

    2011/7/7 Nikita Popov <nikita.ppv@googlemail.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?

    On Wed, Jul 6, 2011 at 3:33 PM, Xinchen Hui wrote:

    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,
    On 07/06/2011 03:06 PM, Hannes Magnusson wrote:
    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

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


    --
    惠新宸        laruence
    Senior PHP Engineer
    http://www.laruence.com

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


    --
    惠新宸        laruence
    Senior PHP Engineer
    http://www.laruence.com


    --
    惠新宸        laruence
    Senior PHP Engineer
    http://www.laruence.com

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedJul 6, '11 at 9:46a
activeAug 23, '11 at 3:44a
posts7
users4
websitephp.net

People

Translate

site design / logo © 2022 Grokbase