FAQ
Hi,

Just looking at the foreach list behaviour and it does this...

$i = [1, 2, 3];
foreach($i as list($a, $b))
var_dump($a, $b);

Outputs....

NULL
NULL
NULL
NULL
NULL
NULL

There is no test I can see covering this, so cannot tell if its
expected.

To me, $i does not meet the expected format, so should be some sort of
error happening.

Jared

Search Discussions

  • Laruence at Sep 3, 2012 at 2:43 am
    Hi:
    this is expected behavior, like:
    <?php
    list($a, $b) = 1;
    var_dump($a);

    thanks

    On Mon, Sep 3, 2012 at 7:07 AM, Jared Williams
    wrote:
    Hi,

    Just looking at the foreach list behaviour and it does this...

    $i = [1, 2, 3];
    foreach($i as list($a, $b))
    var_dump($a, $b);

    Outputs....

    NULL
    NULL
    NULL
    NULL
    NULL
    NULL

    There is no test I can see covering this, so cannot tell if its
    expected.

    To me, $i does not meet the expected format, so should be some sort of
    error happening.

    Jared


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


    --
    Laruence Xinchen Hui
    http://www.laruence.com/
  • Derick Rethans at Sep 3, 2012 at 8:20 am

    On Mon, 3 Sep 2012, Laruence wrote:
    On Mon, Sep 3, 2012 at 7:07 AM, Jared Williams wrote:

    Just looking at the foreach list behaviour and it does this...

    $i = [1, 2, 3];
    foreach($i as list($a, $b))
    var_dump($a, $b);

    Outputs....

    NULL
    NULL
    NULL
    NULL
    NULL
    NULL

    There is no test I can see covering this, so cannot tell if its
    expected.

    To me, $i does not meet the expected format, so should be some sort of
    error happening.
    this is expected behavior, like:
    <?php
    list($a, $b) = 1;
    var_dump($a);
    Ew, that's quite nasty (in both cases). Is there a way how we could turn
    those into a notice or so?

    cheers,
    Derick

    --
    http://derickrethans.nl | http://xdebug.org
    Like Xdebug? Consider a donation: http://xdebug.org/donate.php
    twitter: @derickr and @xdebug
    Posted with an email client that doesn't mangle email: alpine
  • Laruence at Sep 3, 2012 at 8:37 am

    On Mon, Sep 3, 2012 at 4:20 PM, Derick Rethans wrote:
    On Mon, 3 Sep 2012, Laruence wrote:
    On Mon, Sep 3, 2012 at 7:07 AM, Jared Williams wrote:

    Just looking at the foreach list behaviour and it does this...

    $i = [1, 2, 3];
    foreach($i as list($a, $b))
    var_dump($a, $b);

    Outputs....

    NULL
    NULL
    NULL
    NULL
    NULL
    NULL

    There is no test I can see covering this, so cannot tell if its
    expected.

    To me, $i does not meet the expected format, so should be some sort of
    error happening.
    this is expected behavior, like:
    <?php
    list($a, $b) = 1;
    var_dump($a);
    Ew, that's quite nasty (in both cases). Is there a way how we could turn
    those into a notice or so?
    Hi:

    yeah, we can trigger a notice if the container is not a array.

    but maybe deserve a RFC?

    thanks
    cheers,
    Derick

    --
    http://derickrethans.nl | http://xdebug.org
    Like Xdebug? Consider a donation: http://xdebug.org/donate.php
    twitter: @derickr and @xdebug
    Posted with an email client that doesn't mangle email: alpine


    --
    Laruence Xinchen Hui
    http://www.laruence.com/
  • Pierre Joye at Sep 3, 2012 at 9:28 am
    hi,
    On Mon, Sep 3, 2012 at 10:36 AM, Laruence wrote:
    On Mon, Sep 3, 2012 at 4:20 PM, Derick Rethans wrote:
    On Mon, 3 Sep 2012, Laruence wrote:
    On Mon, Sep 3, 2012 at 7:07 AM, Jared Williams wrote:

    Just looking at the foreach list behaviour and it does this...

    $i = [1, 2, 3];
    foreach($i as list($a, $b))
    var_dump($a, $b);

    Outputs....

    NULL
    NULL
    NULL
    NULL
    NULL
    NULL

    There is no test I can see covering this, so cannot tell if its
    expected.

    To me, $i does not meet the expected format, so should be some sort of
    error happening.
    this is expected behavior, like:
    <?php
    list($a, $b) = 1;
    var_dump($a);
    Ew, that's quite nasty (in both cases). Is there a way how we could turn
    those into a notice or so?
    Hi:

    yeah, we can trigger a notice if the container is not a array.

    but maybe deserve a RFC?
    I do not think it is necessary. It is an improvement of this newly
    added feature and list.

    Cheers,
    --
    Pierre

    @pierrejoye
  • Laruence at Sep 3, 2012 at 9:35 am

    On Mon, Sep 3, 2012 at 5:28 PM, Pierre Joye wrote:
    hi,
    On Mon, Sep 3, 2012 at 10:36 AM, Laruence wrote:
    On Mon, Sep 3, 2012 at 4:20 PM, Derick Rethans wrote:
    On Mon, 3 Sep 2012, Laruence wrote:
    On Mon, Sep 3, 2012 at 7:07 AM, Jared Williams wrote:

    Just looking at the foreach list behaviour and it does this...

    $i = [1, 2, 3];
    foreach($i as list($a, $b))
    var_dump($a, $b);

    Outputs....

    NULL
    NULL
    NULL
    NULL
    NULL
    NULL

    There is no test I can see covering this, so cannot tell if its
    expected.

    To me, $i does not meet the expected format, so should be some sort of
    error happening.
    this is expected behavior, like:
    <?php
    list($a, $b) = 1;
    var_dump($a);
    Ew, that's quite nasty (in both cases). Is there a way how we could turn
    those into a notice or so?
    Hi:

    yeah, we can trigger a notice if the container is not a array.

    but maybe deserve a RFC?
    I do not think it is necessary. It is an improvement of this newly
    added feature and list.
    Hi:
    if we fixed this, what about following example:

    <?php

    $num = NULL;

    echo $num["xxx"];


    does this also deserve a notice?

    thanks
    Cheers,
    --
    Pierre

    @pierrejoye


    --
    Laruence Xinchen Hui
    http://www.laruence.com/
  • Andrew Faulds at Sep 3, 2012 at 12:02 pm

    Laruence wrote:
    Hi:
    if we fixed this, what about following example:

    <?php

    $num = NULL;

    echo $num["xxx"];


    does this also deserve a notice?

    thanks
    No because NULL is just the first element in implicit array conversion


    --
    Laruence Xinchen Hui
    http://www.laruence.com/

    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: http://www.php.net/unsub.php
    --
    Sent from my Android phone with K-9 Mail.
    Andrew Faulds
    http://ajf.me/
  • Sherif Ramadan at Sep 3, 2012 at 5:35 pm

    On Mon, Sep 3, 2012 at 4:20 AM, Derick Rethans wrote:
    Ew, that's quite nasty (in both cases). Is there a way how we could turn
    those into a notice or so?

    cheers,
    Derick
    Sorry, hit reply instead of reply-all...

    list($a,$b) = 1;
    var_dump($a,$b);
    /*
    NULL
    NULL
    */

    This doesn't throw notices anywhere else... why should it throw
    notices in foreach? I guess the only logical answer would be to notify
    you if you were using scalar values with foreach and list, but then we
    don't notify you if you're using scalar values with list anywhere else
    in the language anyway. I'm starting to see huge inconsistencies with
    how list is being implemented in foreach.
  • Andrew Faulds at Sep 3, 2012 at 5:37 pm

    On 03/09/12 18:35, Sherif Ramadan wrote:
    On Mon, Sep 3, 2012 at 4:20 AM, Derick Rethans wrote:
    Ew, that's quite nasty (in both cases). Is there a way how we could turn
    those into a notice or so?

    cheers,
    Derick
    Sorry, hit reply instead of reply-all...

    list($a,$b) = 1;
    var_dump($a,$b);
    /*
    NULL
    NULL
    */

    This doesn't throw notices anywhere else... why should it throw
    notices in foreach? I guess the only logical answer would be to notify
    you if you were using scalar values with foreach and list, but then we
    don't notify you if you're using scalar values with list anywhere else
    in the language anyway. I'm starting to see huge inconsistencies with
    how list is being implemented in foreach.
    Possibly more importantly, since 1 should cast to, er, [1] (I think...),
    why is $a === NULL?

    --
    Andrew Faulds
    http://ajf.me/
  • Sherif Ramadan at Sep 3, 2012 at 5:46 pm

    On Mon, Sep 3, 2012 at 1:36 PM, Andrew Faulds wrote:
    On 03/09/12 18:35, Sherif Ramadan wrote:
    On Mon, Sep 3, 2012 at 4:20 AM, Derick Rethans wrote:

    Ew, that's quite nasty (in both cases). Is there a way how we could turn
    those into a notice or so?

    cheers,
    Derick
    Sorry, hit reply instead of reply-all...

    list($a,$b) = 1;
    var_dump($a,$b);
    /*
    NULL
    NULL
    */

    This doesn't throw notices anywhere else... why should it throw
    notices in foreach? I guess the only logical answer would be to notify
    you if you were using scalar values with foreach and list, but then we
    don't notify you if you're using scalar values with list anywhere else
    in the language anyway. I'm starting to see huge inconsistencies with
    how list is being implemented in foreach.
    Possibly more importantly, since 1 should cast to, er, [1] (I think...), why
    is $a === NULL?

    --
    Andrew Faulds
    http://ajf.me/

    It should absolute not cast anything. list($a, $b) = $c; is the
    equivalent of saying $a = $c[0]; $b = $c[1]; In this case $c just
    happens to be a scalar value and as such you can not derive anything
    from the scalar value in that context. It is implicitly null.
  • Andrew Faulds at Sep 3, 2012 at 5:51 pm

    On 03/09/12 18:46, Sherif Ramadan wrote:
    It should absolute not cast anything. list($a, $b) = $c; is the
    equivalent of saying $a = $c[0]; $b = $c[1]; In this case $c just
    happens to be a scalar value and as such you can not derive anything
    from the scalar value in that context. It is implicitly null.
    Ah, I guess I'm confusing GML and PHP array semantics, somehow... my bad.

    --
    Andrew Faulds
    http://ajf.me/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedSep 2, '12 at 11:07p
activeSep 3, '12 at 5:51p
posts11
users6
websitephp.net

People

Translate

site design / logo © 2022 Grokbase