Re: Foreach list behaviour
| From: | Laruence | Date: | Mon, 03 Sep 2012 09:35:32 +0000 |
| Subject: | Re: Foreach list behaviour | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62716@lists.php.net to get a copy of this message | ||
On Mon, Sep 3, 2012 at 5:28 PM, Pierre Joye <pierre.php@gmail.com> wrote:
> hi,
>
> On Mon, Sep 3, 2012 at 10:36 AM, Laruence <laruence@php.net> wrote:
>> On Mon, Sep 3, 2012 at 4:20 PM, Derick Rethans <derick@php.net> wrote:
>>> On Mon, 3 Sep 2012, Laruence wrote:
>>>
>>>> On Mon, Sep 3, 2012 at 7:07 AM, Jared Williams <jared.williams@ntlworld.com>
>>>> 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/