Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112736 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 5639 invoked from network); 3 Jan 2021 18:42:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Jan 2021 18:42:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 14C561804D4 for ; Sun, 3 Jan 2021 10:17:47 -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=0.0 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11olkn2097.outbound.protection.outlook.com [40.92.18.97]) (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, 3 Jan 2021 10:17:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fxoZv98mC+EB5pLDnt4CE49Lk0D2vJA7UbOqqrpSFMeT56c9KQrCf0zvaTHPDHE+sXu8lk/iRHUpeOTC9LS9KZrymiIR5qOlmF57PnhQKs/IgujJ0w31ND2mGuc0sLt6PZgNvId71J4NdbLlyzAtN6tkJeQGo2RCMaFOQk+CcodIOq3f6pqPrz4nNVZ9cYe3bwYkN0MsiHTRR7poPI13YFjmwTn2mD0kCH+cp1xi2IUQXQGcdnJA2hnnWOXsjHiqwbwqwWysNpzvt9l1gwSYe1zuPAK1b5UYClJ/lf8x8mCpp4DoHVKVyQJmYAoOKSXiP5LooHycXYrC2ixnr7RgNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v3Lb4mEJm8s3cfRgOGCuoTLXF3pm38T3gmIWhPuO7Mw=; b=QJQmO5lW+UvOKNBDIosHyIhF1N9tWYRJ/DbaMh68HEg93LlGFC58GoEwJP5bwMlFulfLjY15bDBbOpoYYvCQTnlmkOjQVBQcypNE7fv8FStG5x1Nozu28w5N53fBEuUjzfmStdnrUPJdXe5zKTsG8V8YC+sTMqr2FmEgJoXd5pTTcMBFpNIWQC2O9mbwIX2KLbT943+56UaWhksjBSwzZYdwk3r0BJVZM2F6ebegVv63NOHzaDlmV7/YyY7fU0c9XHrc5mwsaXF1hUIJtNb64Zb9k4j11HPvZWUhAYEbIe97YPhYBzHl16HLPyb/hJPF0vQ0dBqCDaHuoA5cPyYM+w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v3Lb4mEJm8s3cfRgOGCuoTLXF3pm38T3gmIWhPuO7Mw=; b=FOe7eQZnkJBaWnqYKBe6qbp2O9QLc/7IZtCyJvE2PcOtMh+s10r3GBLXzdYlbt2TexDzuzu2HVDsD6b8vZOhxYDUDL5e9Wlgv33pPnVpupBH5RfGKD23gP3/zdS7AFWR5u5db/sv6OCPHF1CJfBrpypztpyNcQvdLAy6LlVRzcgihY/sY7Qxhxw4WRqjBUgCrRl/x9lABgbQLHy+rDHnNatJnr1icr2Xhrx9ITmJgY+fqDoq3hxUu5FO/r0nbBM8psN4qx2w8AEXtcFkJy+Ywa/BqgQKcgLnu/Is3ctjCqjG0FlPLbaDWG3rLNvEKn2EBFdgPAX++oa7taK1kUBY4w== Received: from BN8NAM11FT048.eop-nam11.prod.protection.outlook.com (2a01:111:e400:fc4b::42) by BN8NAM11HT082.eop-nam11.prod.protection.outlook.com (2a01:111:e400:fc4b::240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.23; Sun, 3 Jan 2021 18:17:45 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:fc4b::51) by BN8NAM11FT048.mail.protection.outlook.com (2a01:111:e400:fc4b::373) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.23 via Frontend Transport; Sun, 3 Jan 2021 18:17:45 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::b4c4:dc11:5337:821d]) by DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::b4c4:dc11:5337:821d%4]) with mapi id 15.20.3721.024; Sun, 3 Jan 2021 18:17:44 +0000 To: "internals@lists.php.net" Thread-Topic: [RFC] Add is_list(mixed $value): bool to check for list-like arrays Thread-Index: AQHW1m7vogEIYJkiwEyrC80th3/gm6oWSyBg Date: Sun, 3 Jan 2021 18:17:44 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:520DEED6D0D726354BD9857775275A0C2CF2196887E4EE94DD1D89578BE78386;UpperCasedChecksum:DFB829F8D871F6ED9A2B2739B7E29258B2A777C311641308EA191A83197837F8;SizeAsReceived:6954;Count:44 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [O2SGF0ENwn54LzocMXRwAlQ3Qr1Yho5UOLqsmTFLXaI=] x-ms-publictraffictype: Email x-incomingheadercount: 44 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 0f0e7516-3f86-42ab-9845-08d8b013de15 x-ms-traffictypediagnostic: BN8NAM11HT082: x-ms-exchange-minimumurldomainage: externals.io#1645 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: BhF7/xHDI6xuRRlLFayAKXkbGp8/9m6D1EdS5of5p5D4vUIslCAckA7nNulZUS8YSj7J6LxzhoaKJ1JuwTXSJdFQEwvjQekyBWRzTEb8WQ9FprePMHw3/u2sa+vN8pXMVxip7zhwk7SESJPR+49RvHP5GVTGIlqNC6Gu2AGTvJy1bEMX4vqEHXmlSu3HaifvFHvenbvXpCIsCemY6f0fJSNEdb9zf2HqPnVmxhN81q4Ic7i5i6PegXA7xN6Kbvy8peK/p8yh34rhJvpcw5mWlHtIH1cwe4PzgDYZg4AUTJA= x-ms-exchange-antispam-messagedata: E/M8P37pI4wLMHBPaBlyz/PYvl6BudpJuDFK1DoPoW+uIyyWi87VU81KlkfVlG+F+5St6J4dUvyl4aOiul4gqVRoqEo/Zr1XQsFmnUSECmtMzdk4OSVYid2UiPkcqkqfOdt2J6l1jNB+PcyHjMdLAw== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT048.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 0f0e7516-3f86-42ab-9845-08d8b013de15 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Jan 2021 18:17:44.9389 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8NAM11HT082 Subject: Re: [RFC] Add is_list(mixed $value): bool to check for list-like arrays From: tysonandre775@hotmail.com (tyson andre) Hi internals,=0A= =0A= > I've created the RFC https://wiki.php.net/rfc/is_list=0A= > =0A= > This adds a new function `is_list(mixed $value): bool` that will return t= rue=0A= > if the type of $value is array and the array keys are `0 .. count($value)= -1` in that order.=0A= >=0A= > It's well-known that PHP's `array` data type is rare among programming la= nguages=0A= > in that it supports both integer and string keys=0A= > and that iteration order is important and guaranteed.=0A= > (it is used for overlapping use cases - in many other languages, both vec= tors/lists/arrays and hash maps are available)=0A= > =0A= > While it is possible to efficiently check that something is an array,=0A= > that array may still have string keys, not start from 0, have missing arr= ay offsets,=0A= > or contain out of order keys.=0A= > =0A= > It can be useful to verify that the assumption that array keys are consec= utive integers is correct,=0A= > both for data that is being passed into a module or for validating data b= efore returning it from a module.=0A= > However, because it's currently inconvenient to do that, this has rarely = been done in my experience.=0A= > =0A= > In performance-sensitive serializers or data encoders, it may also be use= ful to have an efficient check to distinguish lists from associative arrays= .=0A= > For example, json_encode does this when deciding to serialize a value as = [0, 1, 2] instead of {=930=94:0,=932=94:1,=931=94:1}=0A= > for arrays depending on the key orders.=0A= > =0A= > Prior email threads/PRs have had others indicate interest in the ability = to efficiently check=0A= > if a PHP `array` has sequential ordered keys starting from 0=0A= > =0A= > https://externals.io/message/109760 =93Any interest in a list type?=94=0A= > https://externals.io/message/111744 =93Request for couple memory optimize= d array improvements=94=0A= > Implementation: https://github.com/php/php-src/pull/6070 (some discussion= is in the linked PR it was based on)=0A= =0A= Due to concerns about naming causing confusion with theoretical potential f= uture changes to the language,=0A= I've updated https://wiki.php.net/rfc/is_list to use the name `is_array_and= _list(mixed $value): bool` instead.=0A= (e.g. what if php used the reserved word `list` to add an actual list type = in the future, and is_list() returned false for that.)=0A= =0A= I plan to start voting on the RFC in a few days.=0A= =0A= Thanks,=0A= - Tyson=