Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112571 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 39894 invoked from network); 21 Dec 2020 02:37:29 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Dec 2020 02:37:29 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8E16C1804D1 for ; Sun, 20 Dec 2020 18:09:49 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-il1-f180.google.com (mail-il1-f180.google.com [209.85.166.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 20 Dec 2020 18:09:48 -0800 (PST) Received: by mail-il1-f180.google.com with SMTP id 75so7512757ilv.13 for ; Sun, 20 Dec 2020 18:09:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=benramsey.com; s=google; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=b/dwGkPJfZHM8Zwpr01LUvQlqX+7ZZv7LwXZsGSXRCg=; b=RDUXkxbgekdBtZo4gamuPd/hlzRO+jmTH4lRD15JL6EVVXzt+1yOFItQ18RQ8rZFd6 5sLn6EiXSC4ceT4cCeqdygllztPaBf7OhentMmPRfzv6pPcPLGUGG2WORCrSEf6kiLwR lu6mKyuMOUMrl3DINst5p5WwaRjw3/DsdOrJXA1Qc2SMWFZglO2MBFYvMwvv/pqx6Zav IGOs9/xyL5WaIzmCvIXzvv3Kp5BhikHTmuMD0qdZQVwEIvvloS556k6kjBLJcko2chMS CEp/9xrmJatGhTQrHxCCxDj+ltQd1L2eRo6njNulHSl4cy7KY6b4cb8XN0ELW380fr2X GJ4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=b/dwGkPJfZHM8Zwpr01LUvQlqX+7ZZv7LwXZsGSXRCg=; b=klOe2Vs8X/43S8MX3ikP47SBKLoPA9fRKVaAT7PxvQwZRMDOTyfVwVbszQnbcCqfvX R1Y5PB47i0zw3ZnB7lQkyQt9LlVHGmfSsDipnOZmJ1CCy9v4bi2/5yVz4k37LAc/nCnL y4ScgtiKITPLu7EY257MegLpe3DvXU471cFwd8x6wg/HzzyOKSXM5KU/a9mJTjOJ8Wnh nogQLgzveQ7omQWciYKOl9G8jl6olFuWHY2Ulo8ZXuJwK3+Fp/IHuYDP1eCTNTqYhaXP DIJVClzAE6x+2Z3cxAHaeOdmNsnCsJF0EXd/tnDX8i8S/gIW7JEgr5LSufQtWBZlCJ0d fWJA== X-Gm-Message-State: AOAM5304XNBdey3qzi9HMCf8+WevOLmbS1EOa8Yv6bnus4CFU/W4wdJh /nACnAXhsKFSK0rHmX9SU3aEvw== X-Google-Smtp-Source: ABdhPJzYSwBc3f85uMWYVCHqCVRhZMeTY6XUFbDQsyftesxSD7JnCFgJG5YTviTug9fZTAp5U7dfyw== X-Received: by 2002:a92:ca46:: with SMTP id q6mr14539191ilo.278.1608516588315; Sun, 20 Dec 2020 18:09:48 -0800 (PST) Received: from [10.10.42.56] ([96.61.105.82]) by smtp.gmail.com with ESMTPSA id c15sm11741034ils.87.2020.12.20.18.09.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Dec 2020 18:09:47 -0800 (PST) Message-ID: <94748D59-630B-4EE2-8106-B68AA4E449D2@benramsey.com> Content-Type: multipart/signed; boundary="Apple-Mail=_2DC63FE8-2C8F-4E44-9C6B-C58DFCF30703"; protocol="application/pgp-signature"; micalg=pgp-sha256 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.40.0.2.32\)) Date: Sun, 20 Dec 2020 20:09:46 -0600 In-Reply-To: Cc: "internals@lists.php.net" To: tyson andre References: X-Mailer: Apple Mail (2.3654.40.0.2.32) Subject: Re: [PHP-DEV] [RFC] Add is_list(mixed $value): bool to check for list-like arrays From: ben@benramsey.com (Ben Ramsey) --Apple-Mail=_2DC63FE8-2C8F-4E44-9C6B-C58DFCF30703 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Dec 19, 2020, at 19:43, tyson andre > wrote: >=20 > It can be useful to verify that the assumption that array keys are > consecutive integers is correct, both for data that is being passed > into a module or for validating data before returning it from a > module. However, because it's currently inconvenient to do that, this > has rarely been done in my experience. I think there are some places where `is_list()` could be unintuitive to those who don=E2=80=99t understand some of the idiosyncrasies of PHP. For example, with $a =3D ['foo', 'bar', 'baz=E2=80=99]; `is_list()` will return `true`, but if you run `$a` through `asort()`, `is_list()` will return `false` because the keys are no longer consecutive integers, but is there any doubt this is still a list? Maybe in a pure sense, it=E2=80=99s not, but I think this could be = confusing. But now, if we do $b =3D array_merge($a, ['qux', 'quux']); `$b` is now back to being a list, so `is_list($b)` returns `true`. While I understand the convenience `is_list()` provides--I myself have implemented the opposite of this numerous times (e.g., `is_dict()`)--it comes close to implying a data type that PHP doesn=E2=80=99= t have, and I think this could give a false sense of type-safety-ness when using this function to check whether something is a 0-indexed array. Cheers, Ben --Apple-Mail=_2DC63FE8-2C8F-4E44-9C6B-C58DFCF30703 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- iHUEAREIAB0WIQToXQMR3fpbrPOmEOewLZeYnIwHGwUCX+AD6gAKCRCwLZeYnIwH G6e0AP435gQQvPV+A4mDIRRlPzgKqKHCegObj394m4i2P3GNIAD9FLqHZNSzU+9A GnU6IW2l7Aa61S7AjZR6pP1Mxfic+Ho= =QcgP -----END PGP SIGNATURE----- --Apple-Mail=_2DC63FE8-2C8F-4E44-9C6B-C58DFCF30703--