Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112565 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 172 invoked from network); 20 Dec 2020 17:36:23 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 20 Dec 2020 17:36:23 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 51B161804B1 for ; Sun, 20 Dec 2020 09:08:36 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 20 Dec 2020 09:08:35 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 002CB5BC for ; Sun, 20 Dec 2020 12:08:33 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute4.internal (MEProxy); Sun, 20 Dec 2020 12:08:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=IvnWEbuaWBaoFVudZrXHKfIUq6fJXsKYqJLeXKpxK zY=; b=drEnLLkYj5Hvdwm+g3LNDCm6IJOnaMBny3pT4bEV7Q0NcmhhRG98eHGSL LhEE/QWGmLRKOnufXc1slBoT8On3D/JSJvMLovHR3J7Px/fQC65zpoPZmsfebj0/ Zzngu/RbKKdLSjwQsLuOg5rTj+Neegwu7F3YQfcUi9i0l1Dg7R2gchLwxxT1WdHi V6FOzrzMkXX47kXzZthyWA8YZttDW8naBHsIm9wh+23EiehjCQPcpNqcBJdAN9XM CNFYCaWR9IPS9IF2IoXmVqv2XDGmy9yKB0sf9aPemlHVOV6ePF3KZCx/ufudsiky AYS2F0w+RlTpqM3iywKvGai3AJjjg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvddttddguddtfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdfn rghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrd gtohhmqeenucggtffrrghtthgvrhhnpeelteeltdehtdetkefgleekgeefhfeftedtheei feekheehteetfeffhfehgefftdenucffohhmrghinhepphhhphdrnhgvthdpvgigthgvrh hnrghlshdrihhopdhgihhthhhusgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecu rfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 1F8B814200A2; Sun, 20 Dec 2020 12:08:33 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.1-61-gb52c239-fm-20201210.001-gb52c2396 Mime-Version: 1.0 Message-ID: <1b92dea2-667f-4de7-9de9-0aa41f56f81e@www.fastmail.com> In-Reply-To: References: Date: Sun, 20 Dec 2020 11:08:11 -0600 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: =?UTF-8?Q?Re:_[PHP-DEV]_[RFC]_Add_is=5Flist(mixed_$value):_bool_to_check?= =?UTF-8?Q?_for_list-like_arrays?= From: larry@garfieldtech.com ("Larry Garfield") On Sat, Dec 19, 2020, at 7:43 PM, tyson andre wrote: > Hi internals, >=20 > I've created the RFC https://wiki.php.net/rfc/is_list >=20 > This adds a new function `is_list(mixed $value): bool` that will retur= n=20 > true > if the type of $value is array and the array keys are `0 ..=20 > count($value)-1` in that order. >=20 > It's well-known that PHP's `array` data type is rare among programming= =20 > languages > in that it supports both integer and string keys > and that iteration order is important and guaranteed. > (it is used for overlapping use cases - in many other languages, both=20= > vectors/lists/arrays and hash maps are available) >=20 > While it is possible to efficiently check that something is an array, > that array may still have string keys, not start from 0, have missing=20= > array offsets, > or contain out of order keys. >=20 > It can be useful to verify that the assumption that array keys are=20 > consecutive integers is correct, > both for data that is being passed into a module or for validating dat= a=20 > before returning it from a module. > However, because it's currently inconvenient to do that, this has=20 > rarely been done in my experience. >=20 > In performance-sensitive serializers or data encoders, it may also be=20= > useful to have an efficient check to distinguish lists from associativ= e=20 > arrays. > For example, json_encode does this when deciding to serialize a value=20= > as [0, 1, 2] instead of {=E2=80=9C0=E2=80=9D:0,=E2=80=9C2=E2=80=9D:1,=E2= =80=9C1=E2=80=9D:1} > for arrays depending on the key orders. >=20 > Prior email threads/PRs have had others indicate interest in the=20 > ability to efficiently check > if a PHP `array` has sequential ordered keys starting from 0 >=20 > https://externals.io/message/109760 =E2=80=9CAny interest in a list ty= pe?=E2=80=9D > https://externals.io/message/111744 =E2=80=9CRequest for couple memory= =20 > optimized array improvements=E2=80=9D > Implementation: https://github.com/php/php-src/pull/6070 (some=20 > discussion is in the linked PR it was based on) >=20 > Thanks, > - Tyson Well, since I'm quoted... :-) I'm fine with this, but have one question and one correction: * If we do eventually end up with list/vec types, would the naming here = conflict at all? Or would it cause confusion and name collision? (Inse= rt name bikeshedding here.) * The last quote, from me, has a small error. The last sentence shouldn= 't be a bullet point but its own paragraph, after the list is complete. --Larry Garfield