On Wed, Jun 20, 2018 at 8:09 AM Rowan Collins <rowan.coll...@gmail.com> wrote:
>
> On 20 June 2018 at 14:55, Levi Morrison <le...@php.net> wrote:
>>
>>
>>     if ([$key, $value] = array_last($input) {
>>         // do something
>>     }
>>
>
>
> Unfortunately, this won't work. I didn't know list() could even be used as an 
> expression, but apparently if it is, it evaluates to the whole array on its 
> right-hand side, which makes sense.
>
> So, if array_last([]) returns [null, null], then [$key, 
> $value]=array_last([]) will also evaluate to [null, null]. Since that's not 
> an empty array (it has two elements in it), it will evaluate to true. 
> https://3v4l.org/lIEa1
>
> If, on the other hand, array_last([]) returned something empty, like [], the 
> list() assignment would throw Notices for the implicit access to elements [0] 
> and [1] of the empty array. https://3v4l.org/qhq5R

It returns `?array`. So either `null` or `[$key, $value]`. There are
no notices; sorry for the lack of detail.

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

Reply via email to