Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102513 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82281 invoked from network); 28 Jun 2018 13:02:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jun 2018 13:02:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=enno.woortmann@web.de; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=enno.woortmann@web.de; sender-id=pass Received-SPF: pass (pb1.pair.com: domain web.de designates 212.227.17.12 as permitted sender) X-PHP-List-Original-Sender: enno.woortmann@web.de X-Host-Fingerprint: 212.227.17.12 mout.web.de Received: from [212.227.17.12] ([212.227.17.12:48249] helo=mout.web.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B0/B9-01794-F4CD43B5 for ; Thu, 28 Jun 2018 09:02:07 -0400 Received: from [10.129.18.221] ([194.76.42.30]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0Ls8xf-1gIGUn0L6d-013zgV; Thu, 28 Jun 2018 15:02:02 +0200 To: Rowan Collins , Marc Bennewitz Cc: PHP internals References: <75db877c-ef0b-7d3b-48a8-9879d90352b0@web.de> <3242366.BL9MUqXe46@vulcan> <2241856.Iz1GuBRvza@vulcan> Message-ID: Date: Thu, 28 Jun 2018 15:02:01 +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:NO3YgNjCP3cfMkzcGLgfzs/k6jJejc5IjyYXbdC/kKL6cx70Ool wU2W4NoJFBeiWx/F/oqN5xLF5y3KOHdHFbYdFNGofYUegl7FbnBcPpZh9ZFn0uFg0w6PkTl qEqzLplHKTKXT98BOVkmJ8ioP7HTn1zQFgC00i13SSzQLNysE9dCu9SKPjjcP5Qk4RPSUOC PquMSIq9T3kW2OWgXxr7Q== X-UI-Out-Filterresults: notjunk:1;V01:K0:aBCeETHe4ag=:q0r/R6l2DQJ3bNkyRmOBPu 1CCCj35vcksyviTG1hApWR+ayrJFEG9py4Uip8/BW+C6QgigeVz0m0T/Yqw3o7Xq9xELzsA7o C2D7woDxC8OdMAdF3Wy+mQ/dFEJbRORG0XKEgRn+cUYfLWUiQFYzWEikTInjQLNPE6S0K/ny4 um/G3gygNeCmCmO+gQ/C912/4uFCYg2WZINwiPiomrKJPqKWlC8K0D8ywFNY4S1Ls0iIBGXwF 1RNa6/BaHlpWF7/Sx1k0hsuzf252d55k+sUUw4508aEijPhC5iCrNcyEYXHcmBnmGkkAcNE3c lD4j9CDOQ0ByETAukxxIPnmSyEukJ34wCJ+A6Qzes8z9pcob3thSvTqgNANr6EDwAOQ0FIqi+ TNQvJYAH7LepOQPwUe2Kpw4hPnt1gZ+YZHsA2nYcopuknEC++0oE2FUkaCj/T9hm2a8IuTi4v jPBr7PmdwOJ91lqYgtJKDD4CBy3VLTc3dkJGOkB8g7vOnis7oMioFcXrUTt45pbZZB8LJqx+i zJ/Tz8/h7rYn59IDtfioL83P8oiYBJgadFXh1GFXU6Ecijsb1rgrbJo+LBLOgTbm0EgKXqQpF apIpKp2GHo+Awauacg+ANx+97i83GVGnuiw42DqC8SWVdeR+gAwG7qsMolZm7H+DtIaJ5odtL Mg8wFFPdUTjmgu2vR8PoPKIvbcUrfZAKwsW6kG+CLSF0xlC1x1Dq0gMvY9+G1N0QPEkjwOki0 i7S24u2KrFaYH3YflaBX7+RjKTcrT2phTTogycI35jtV9bALYdKWpA/zJ2R0A7MX22wZZMxnO rMBMPoh Subject: Re: [PHP-DEV] [RFC][Under Discussion] Add functions array_key_first()and array_key_last() From: enno.woortmann@web.de ("Woortmann, Enno") Am 26.06.2018 um 16:42 schrieb Rowan Collins: > On 26 June 2018 at 08:58, Marc Bennewitz wrote: > >> Hi all, >> >> I just want to add some information that I feel it's missing in that >> discussion - I'm sorry if it was mentioned already. >> >> 1. It's already possible to extract the key and value of any index >> position of an array using array_slice: https://3v4l.org/mib99 >> >> 2. "array_[key|value]_[first|last]($array)" is in my opinion not a good >> option as it lacks the possibility to extract key/value from any position. >> Something like "array_[key|value]_index($array, $index)" where $index >> would be the index position or negative index position from right. > > The big advantage of separate functions is that they make the intent clear; > we could combine all four functions into one: array_index(int $position, > bool $key), but "array_key_last($something)" is a lot clearer to read than > "array_index($something, -1, true)". Are there actually use cases for > getting "the 5th key from the end of the array", common enough to make "the > last key in the array" harder to write? > > Regards, As well as Rowan I don't see use cases for fetching keys/values at any position inside the array for justifying to break up the current readable function signatures. Combining multiple use cases and tasks into a single function always offends the single responsibility principle (compare my previous mail) and thus should be avoided. Are there other opinions concerning this topic? I'd like to finish the discussion soon and move on to the voting phase. Regards, Enno