Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112560 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 48123 invoked from network); 20 Dec 2020 02:11:03 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 20 Dec 2020 02:11:03 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F13701804C6 for ; Sat, 19 Dec 2020 17:43:06 -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-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11olkn2067.outbound.protection.outlook.com [40.92.19.67]) (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 ; Sat, 19 Dec 2020 17:43:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P3ClzIkP9s7iAylbtV4YY+F5pKT8gv/2H96jL87ybXBY/DT0IRI6g9KPnv91cI5crUaVgHwpek7216ueFVA5btaMYw0ckkGgepxThS5t6ocYbLVCmIRLPByAc8j7SReylKiRQbxGDGC5w46R9iTYXsC26ItwfzBz3Zdgsct2QyFXkATQImc6/30zGyoY5hWHzlHJlv8JA7RQlnhDk6IHfkYpxrAET0mMXnH2fkH2Nh+7Ma0J19nOvB7XkGOxtPKaGn6I+ZnlsKIdolLBD9Cq+73ZvYjTZ2bDScd05/yxqTN1SLAG4f7Sy/YEb32E6on8omp8fm55M1T7qMchGAdhSw== 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=o68Ge99rTQ3Ucyb740IF4LzDeIfb3fZouzzYFltAZ0g=; b=FvMzsEI79yv3RgDSn7tRjHz1Ch30zqnZ3Y6lmO+k/Rzuv6+B4fKd76GfSc2G40swcXN3H4NSFyR5zslbNLWwM9jKm9Fc+oF5OUsx3UCwjVDjESsKinc3N2qhCFK+/ypnOMBD0nau8cJY+AitlbIlOmSzOSrwWGY5lxwf4CiqbaB1C7PFo+rtFkgtftyUKO3D+/qIo6mmZNYOIwUH9foLCAwLxPkR9IuSN9484cXG4pnp9/pH3FLDal8D3Qb+3GL4Y/GcmvAXcCx35eCA7Gf2GoXue9b4N6FCQItdIstwlVBK6Ik8Q9H0LiEakAnVhRJpa0UuyLjpMpweaIQIyzUpnw== 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=o68Ge99rTQ3Ucyb740IF4LzDeIfb3fZouzzYFltAZ0g=; b=n/+7S2Mx5nOUSbi9D2gbK7SNzFtCd5YP3nsb7/yfSEg4TZu0w5kKL/qJ7W62rsOGQ3zatigF+spo7XmOa9ftJEyhlYFFFiWXh6ThfLaPKham7dKVzJXC28KOgHyDrlXYmQOjZpbBFsBXyoL0lF1P1+VnmVogAfVwgbJagV79DAc7jMOsObuNN3B4WJkxLW72vqCjolef08l2E3nEoLImJwzODBPieP8Ex4Yk0hQ06PfOrukSz9WP+Wlhhoc+2m++gvNmjDcnJYDFlu9mA2pkx/koLTcs3AhhgdgFIyPXd+iVvgUb2QmZxvjvtsQkUDi20LsPCThZDaWa+rx4EMGoMQ== Received: from BN8NAM11FT010.eop-nam11.prod.protection.outlook.com (2a01:111:e400:fc4b::47) by BN8NAM11HT219.eop-nam11.prod.protection.outlook.com (2a01:111:e400:fc4b::280) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3676.25; Sun, 20 Dec 2020 01:43:04 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:fc4b::51) by BN8NAM11FT010.mail.protection.outlook.com (2a01:111:e400:fc4b::309) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3676.25 via Frontend Transport; Sun, 20 Dec 2020 01:43:04 +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.3676.025; Sun, 20 Dec 2020 01:43:04 +0000 To: "internals@lists.php.net" Thread-Topic: [RFC] Add is_list(mixed $value): bool to check for list-like arrays Thread-Index: AQHW1m7vogEIYJkiwEyrC80th3/gmw== Date: Sun, 20 Dec 2020 01:43:04 +0000 Message-ID: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:4A27511A28C3A1FBFFB59CE7D35CEEEA6E5C2055F19BED8CE2DF1BCFAC9A7902;UpperCasedChecksum:6116EE24A105C313AC3C4A9BC9CDA165D8CC3C688366CF07D1E7C6FD5E09657C;SizeAsReceived:6866;Count:41 x-tmn: [U2qQFjmWeETc5GV0WgxHT6u2KZ5tuMWAuJl7xR4EcLpuffWML/Hl+pDhOAjCCg8G] x-ms-publictraffictype: Email x-incomingheadercount: 41 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: ed9bc035-8545-4e86-0fd9-08d8a488980f x-ms-traffictypediagnostic: BN8NAM11HT219: x-ms-exchange-minimumurldomainage: externals.io#1631 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ks1EybFwktTyWJWffeEvSP/AuJ+Ak7laQR05WAUkiVE3NnE2dg1Ua6qENLYGSwPyGLZQDvmMhY5tbGk7uid3ry/505ZzHRgAqVmCHABtAOfWdWgTC6YgfiEfiHLNFaPqwxvRte5DeA+urdERXJafvqmx4DEXGy8dXrORsAz0b13zUlPhvIz3twsHYLp4crE6vVrSM9ey6S3XVHqrypZ95EcxIwCAsIvfN6cOfakNg2pp+5F1DYFJLRKfTRkqM1RJGEKsOvpADVGjaEO5cYa6QNmsF1VFWMKEnopupZI5d54= x-ms-exchange-antispam-messagedata: Wi1zJiSHw8tUhKEp6b7mJ41IluD9h3jjAqSWQ7O0IDiOtVbP8vEsWV5He+K9YDkN11uiIR9IwRm2iDKDhbFrMKx9y8F47WOTGQB33EMMZaA/yLBZTSzYnW0DyRQHkDa34/+2gdlyQ4/k7+N041X9k7dI6XRtDxHpSxwVgGfCaO98jNkWw46dJdAYiH5iFjr2iLtztaTVMfqNC1jXA6Nv1g== 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: BN8NAM11FT010.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: ed9bc035-8545-4e86-0fd9-08d8a488980f X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Dec 2020 01:43:04.5407 (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: BN8NAM11HT219 Subject: [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 tru= e=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 lang= uages=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 vecto= rs/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 array= offsets,=0A= or contain out of order keys.=0A= =0A= It can be useful to verify that the assumption that array keys are consecut= ive integers is correct,=0A= both for data that is being passed into a module or for validating data bef= ore returning it from a module.=0A= However, because it's currently inconvenient to do that, this has rarely be= en done in my experience.=0A= =0A= In performance-sensitive serializers or data encoders, it may also be usefu= l 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 optimized = array improvements=94=0A= Implementation: https://github.com/php/php-src/pull/6070 (some discussion i= s in the linked PR it was based on)=0A= =0A= Thanks,=0A= - Tyson=