Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102324 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77392 invoked from network); 20 Jun 2018 14:11:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jun 2018 14:11:00 -0000 Authentication-Results: pb1.pair.com header.from=levim@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.48 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.215.48 mail-lf0-f48.google.com Received: from [209.85.215.48] ([209.85.215.48:34471] helo=mail-lf0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 52/05-32156-3706A2B5 for ; Wed, 20 Jun 2018 10:10:59 -0400 Received: by mail-lf0-f48.google.com with SMTP id e13-v6so4915562lfc.1 for ; Wed, 20 Jun 2018 07:10:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ABjj8Q97XoqwfFDDCZwmYTVrCQ0c6JkE3mIzdLBf+hI=; b=rYW9jTV8fVMVGO21k6yycZCLLU2Xy3bUN1Cw7bDPKgSAxC5tkHuKWQi+mSU3XinUMx AJsT+umBfZoIimdadzDV2jciv6ocWQtOvEOL8frmanSdXkiLnL1xrScHb7uxF3IWs+Qj mBFkBKRvvGvolP7D4IAN4wIGkjYsGOdqZXR/ih6Pn1PsiCh2+VVCbt8PiZ3/jnZhs2oa ZhE20m0NboUCIonw61YrfLIDV8UZEi2SCvt7sjDtsyf0fjMO4snUc2Ho9kdfsVyG28Aj wc5tOna4cOjcXc94NRPn6jWbRHpERWlPdR/vagMOIHisRAPuLBwfCVmAETBsuPljwhxK zdqQ== X-Gm-Message-State: APt69E3OAVWwChkpfTHYt9I8V1iDrjwhDhQ3wlgI7Cy/bMOunnclUQfQ t7F4Ksz4nJ9VzkcL5Sq2AF/1bwbhLkG47aqGPsg= X-Google-Smtp-Source: ADUXVKIODap5DXE7Gtflbe571QNJ9lqtjLFchOypM9Biz9Ded5muhzTBs35SNhVBbp70C9w2PRqkUm48ASD7KUSp4vQ= X-Received: by 2002:a2e:889a:: with SMTP id k26-v6mr14042664lji.54.1529503856358; Wed, 20 Jun 2018 07:10:56 -0700 (PDT) MIME-Version: 1.0 References: <75db877c-ef0b-7d3b-48a8-9879d90352b0@web.de> <76e4744f-6722-ee49-0325-e4433236f1b1@web.de> <73ac8914-8c9f-e74b-a4f5-f6e39cd96f8f@gmx.de> <3242366.BL9MUqXe46@vulcan> <154ba124-2915-ca36-fa39-5df6726d3b5a@web.de> In-Reply-To: Date: Wed, 20 Jun 2018 08:10:44 -0600 Message-ID: To: Rowan Collins Cc: enno.woortmann@web.de, internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC][Under Discussion] Add functions array_key_first()and array_key_last() From: levim@php.net (Levi Morrison) On Wed, Jun 20, 2018 at 8:09 AM Rowan Collins wrote: > > On 20 June 2018 at 14:55, Levi Morrison 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.