Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102329 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89080 invoked from network); 20 Jun 2018 16:03:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jun 2018 16:03:05 -0000 Authentication-Results: pb1.pair.com header.from=enno.woortmann@web.de; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=enno.woortmann@web.de; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain web.de designates 217.72.192.78 as permitted sender) X-PHP-List-Original-Sender: enno.woortmann@web.de X-Host-Fingerprint: 217.72.192.78 mout.web.de Received: from [217.72.192.78] ([217.72.192.78:33859] helo=mout.web.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8A/D6-32156-7BA7A2B5 for ; Wed, 20 Jun 2018 12:03:05 -0400 Received: from [10.129.18.221] ([194.76.42.30]) by smtp.web.de (mrweb101 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MLgZ5-1fVOSG3Z6R-000qL7; Wed, 20 Jun 2018 18:02:59 +0200 To: Levi Morrison Cc: internals 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> Message-ID: Date: Wed, 20 Jun 2018 18:02:59 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K1:IVXag+x2IQWA3xCAtXK38llk8Lxo2IkUYmUrIgWIeEJYw93SDft o50cM7Bt/n9dlmlt/kYhAEGAwdQyPITZsEzt97+F2aSOXc+pAgQ3a9btWrVwpfb9/foP7ND BboMDTgNDy0v2n191IC1K3BP0lofrTcC0dc17AZ1LQQhdKxNqIkyXHBPYocicpfUVBQ7gr6 ixUrxxwmxk35i+u7Nvi3Q== X-UI-Out-Filterresults: notjunk:1;V01:K0:dif5hrz0gRI=:vk8GHZ945Rgf6/LvUEEkvV nc4OXGx/4gnnwv+xqO4etUVSU18Ohu6npyaipg75YCbU8dT53VnI0wu6YV188m1icEm8YW8WJ 3ngETBQEF0ARphP26hs6q9m99IBD93ZKGS00nnZV5kw4Qhoyj3vZY4Oa+8MjCMv8tKTirNtcd DWDrgQ3qlldScAmDLVaakrAA2LEEvk1JhodAqhtyL0i8NfHsdqzkZ1qSiEH65P0YgWPWQeCH8 WBbLDM8JUyUB7qE23AsOGQsVlJrts5pT7sTUvdS604RJJVKrIn8sb8HsawDjr4Ziy/XBGs3/Z PvcBXyMCf7i1QOZ8R/gCrxdhprUxyQQQUpKjzcRGs1Ii+CTvCE5fqtIeGrTqRrJVygzqjDjId ZCn+Zlp/sNS7yrmKqtIlb9/VELf5R1u4Z1mAzjvUxR0NCVqjduB418bWfCVsjBtjkg1Q7ocvn 9WjfH/rFj7PRvKl28HYQSSjs7OULfIaYedTMC2a7KjZmFGnwEswIdfRERiZWOaROcDvGWJF+D domYjmTcQkOfsDIp1IQODj7+kE2o0wgnT2+cvp3+5AOrzjuqZ19svnSkuDCQkMe+Yl/fgmoul TmlRWn3VS0avU7XotN8fA/gU0asO6m86QMdRpy4ic1M3Ez/QLPA/r7D4u5FuDI35t6OxQuzfd 3ZcQYbEZY2XFVRINd0OX6FrET/xti6IqnLP+SNV3YksGJT13F6+67JI1d/I42r2yjcqv5BFkE Fu0/+YDdpw3SGaWCOMjm0FiyI+46b4bvFuEG0m+DLtKHY6BEXsExlD7rj+HlEUu5wMxYbIFIK dFMzg62 Subject: Re: [PHP-DEV] [RFC][Under Discussion] Add functions array_key_first()and array_key_last() From: enno.woortmann@web.de ("Woortmann, Enno") Am 20.06.2018 um 15:55 schrieb Levi Morrison: > Your wish cannot be granted for `array_value_last` and > `array_value_first`; you cannot know by itself if there is a failure > condition. I can comprehend your issue with the lack of distinctness between the error case and the 'real' array value null without further checks. But in my opinion the required additional checking of the $input is a learned behaviour from existing functions which handle single value elements from an array as reset(), current() and end() will return false for empty arrays or null for invalid data types which are both also valid element values. array_pop() and array_shift() also behave in a comparable way as they return null as well for empty arrays as for non array input. > This is not "clean". In contrast here is with my proposal: > > if ([$key, $value] = array_last($input) { > // do something > } I still think that this proposed syntax is unintuitive and hard to comprehend for the user of the function. I don't think many PHP developers out there know that the condition inside the if will evaluate to null if array_last returns null. Additionally I don't know about any other function where a construct like this has to be used to extract two or more different semantic entities, in this case the key and the value, out of a PHP core function return value. Enno