Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102887 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97844 invoked from network); 17 Jul 2018 12:24:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jul 2018 12:24:45 -0000 Authentication-Results: pb1.pair.com header.from=carusogabriel34@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=carusogabriel34@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.221.42 as permitted sender) X-PHP-List-Original-Sender: carusogabriel34@gmail.com X-Host-Fingerprint: 209.85.221.42 mail-wr1-f42.google.com Received: from [209.85.221.42] ([209.85.221.42:36377] helo=mail-wr1-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 14/88-37178-900ED4B5 for ; Tue, 17 Jul 2018 08:24:43 -0400 Received: by mail-wr1-f42.google.com with SMTP id h9-v6so1071202wro.3 for ; Tue, 17 Jul 2018 05:24:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=38AIn2Msk3fTbqK6EllieYjVWxhyYD9Kbb2+qsNEuTg=; b=o0uxi3fS3H7Cn9NWELdMf8eGVae023yWWS0BK7PWO5/o0iscyKFBK4DAtXUkGq9muA x5RAmTGFbEC/Rx3ynF9Zniqdo+BxRhQzS85aFPVLd+QTefkGWFydbAzEl5gxRvsT8rJe Si82Hd0UIj5FMBmRd2pd80mSZSPtCSX47NwdkFbV0LW3fve506QY2358kdcO14PIGBkX V2uCuWXghvOQgZT/ca+xpySlDDc93gU5vymJn56ntyf1AkhWiBjxZkBK3HXvOCmtzOwD mZSvU5YgOcK+M1g+9s98LCWtLmT7yDoQd7Jw+eiQIqKGq8ntcCjRILHJv2yF+7DG8mnz JwFQ== 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=38AIn2Msk3fTbqK6EllieYjVWxhyYD9Kbb2+qsNEuTg=; b=jCLDcXryCVmQrSzMYfCKCf6FHrqEGpeWiX62/3H3Tv5Cgh9l1UcQVLHy5xJib3VhUH uE/nb+z3RBI+bEF3aHbZFp5zRzu8f1M+m+aqlQ3vnpNr9bdGWxqVhkmtu1mp5xUFKGFs KRwp+DzjM4m/OPqtSK0vjqu+6gwEFYGO0aIug55ac9ShD1JSFxPS7bLfmS1f1fJMZn5L qtp9X4/LW+kJknnLJSEdOKd0mzHD2PleXjCk58XePPjv6YL/Abwbgwm1FXDG0Z8mqZbN t7/k7UlMHgku9jJMjpm+4F2E9bMg3DTQp8Yz60Geubc393Ji/BFdUTwbgXZJ08nzJ+5q 8lHw== X-Gm-Message-State: AOUpUlH0ZTtSUK26qLACD+Z8x0EmGXsgUnDMF2lAtZ8qUrLLlhGm+FhG MoEatEjMzWdOzRX3LyR6IAcOADn+BKgOl5UIn6I= X-Google-Smtp-Source: AAOMgpdQrnrb6VYxl4PQMDZQH59Dgn2iMAEjTXt4qWIri4u3ofOqmQoRnmqnPHG6WHht2DMgIKR4u4+KIxJ6lsdvUCg= X-Received: by 2002:adf:bc03:: with SMTP id s3-v6mr1314716wrg.211.1531830278878; Tue, 17 Jul 2018 05:24:38 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 17 Jul 2018 09:24:24 -0300 Message-ID: To: Levi Morrison Cc: internals Content-Type: multipart/alternative; boundary="000000000000a0f91b057131078a" Subject: Re: [PHP-DEV] Replacing array_slice From: carusogabriel34@gmail.com (Gabriel Caruso) --000000000000a0f91b057131078a Content-Type: text/plain; charset="UTF-8" Hi Levi, thanks for bringing this discussion. Recently I've been scrutinizing array_slice. It's been painful. > > For instance, `$preserve_keys` is totally ignored for string keys. > This was undocumented until Christoph integrated it 2-3 days ago > (thanks, cmb). However, this is really not a good design decision: why > have a parameter that is called `preserve_keys` if the data gets the > final say, especially since there isn't any technical requirement for > this? > > Here's another "fun" behavior: negative offsets whose absolute values > are larger than the size of the array (eg the array has 3 elements and > you pass an offset of -5) will shift the window to begin at zero > instead of truncating the out-of-range values (which is what happens > on the positive side). > > And another: `$length` is a length when it's a positive number, but > it's an offset from the end when it's negative. You could perhaps > convince me that when length is positive it's an offset from the > `$offset` parameter. However, if you look at the design of slicing > functions in other languages (eg Python, Ruby, JavaScript) they take > beginning and ending offsets, not a beginning offset and a length. > > And another: it always iterates from the beginning of the array even > if you are only interested in the last half (somewhat common for > various algorithms that split things in half). > > Fixing `array_slice` would probably do more harm than good at this > stage. Instead I would like to provide an alternative function that > does not have all this baggage, and will have decent performance much > of the time. The best ideas I have for names are not that great: > > - `array_real_slice`? > - `array_slice2`? > > We could also split it into 2 functions, one that preserves keys and > one that doesn't, instead of using a parameter. Any ideas there? > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php A while ago I come up with this discussion in my Twitter, not with a new function, but with a new "operator": https://twitter.com/carusogabriel/status/974610078807613443 What do you think? Thanks, --000000000000a0f91b057131078a--