Re: Foreach list behaviour
| From: | Sherif Ramadan | Date: | Mon, 03 Sep 2012 17:46:32 +0000 |
| Subject: | Re: Foreach list behaviour | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62760@lists.php.net to get a copy of this message | ||
On Mon, Sep 3, 2012 at 1:36 PM, Andrew Faulds <ajf@ajf.me> wrote:
> On 03/09/12 18:35, Sherif Ramadan wrote:
>>
>> On Mon, Sep 3, 2012 at 4:20 AM, Derick Rethans <derick@php.net> 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.