Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112586 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 40476 invoked from network); 22 Dec 2020 02:29:46 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Dec 2020 02:29:46 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 35B931804DD for ; Mon, 21 Dec 2020 18:02:21 -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-io1-f49.google.com (mail-io1-f49.google.com [209.85.166.49]) (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 ; Mon, 21 Dec 2020 18:02:21 -0800 (PST) Received: by mail-io1-f49.google.com with SMTP id p187so10662653iod.4 for ; Mon, 21 Dec 2020 18:02:21 -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=Ytb2Y3eh32gpBBKnvrkCNCOypExNHBdQEPUdY1vtLRg=; b=WnygTU37nJ4Jzn040DfC8MG4jRJ6GbeTjFofP0ML0tGbSh6GRyQ6FPSmB9ydTe/rQg vvC2tlZLXwapjnU3+vzbxBQL/2gTTQjiNS2RHUubcO2MyUhR4JhNX4vGEwKpzFijrCRd XLWQtZxPqtYcq5X4HGgJn3g5u+PLnt5zXwr1A9wbmqIxhx8yemgxp+kwnGJRhXKI5l7z bhHp2xKi1QjL8/Q01Axbysn3rzVsABzV+ZgyaOFe4NhtHhyqSQnZyqtRFoIL30G+4i1h 7ZSEnIBdJXR2WSMahxukMuy9M0IhNaBK6HvFd/viwH6dTJmL5XPKS0aIAyGy+rIg8fhi L/zA== 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=Ytb2Y3eh32gpBBKnvrkCNCOypExNHBdQEPUdY1vtLRg=; b=DzXtyhgiN1SegrA55p2OdVZw5gqyrL/6IOhd2obk45SBYze8spZG69Wb3h3jquZMGY ECVNWwgTx6V1xPejvl43iD2hMlmxB53WZzROpgS0qDomMapkCkj1qZhnzXm8bTd0I+7Z AkejALoV+O+VIqggoN/TV344hlPLHrZQ9XqZMsKVLVgInZt0Uq+SasX+Fu54Qm/HMRoL 9mbBhXeHcSzT00mP+Z7e+io4mOlqJOSQkAfrkSsytw9B+kY81AWB4nHMJvEB4KtODbXZ XvLLIWOOwVGXX4C63WU5jmXcq56DNFWLrvgcfFFWkz6l2pSlFNsj+1hl6BWf6jBqK8IV wOzA== X-Gm-Message-State: AOAM533K1tLsdgdz1zKeMA368+JYe0FC/Ck2cJkRK6BBsxBPuZIWiycU GQNJsETbidcF79QnDMpOOVYhjg== X-Google-Smtp-Source: ABdhPJyFJaKk1xb2U7sOu5T0XTlfMrPQU7w7FR8O1yXyGCDQkpC5U1Oys1gQwFI3/DA3D6wFIudclQ== X-Received: by 2002:a5d:824b:: with SMTP id n11mr16126283ioo.27.1608602540216; Mon, 21 Dec 2020 18:02:20 -0800 (PST) Received: from [10.10.42.56] ([96.61.105.82]) by smtp.gmail.com with ESMTPSA id d18sm14083482ilo.49.2020.12.21.18.02.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Dec 2020 18:02:19 -0800 (PST) Message-ID: <42C458F8-739D-448A-BF35-6BAF0C1C24FC@benramsey.com> Content-Type: multipart/signed; boundary="Apple-Mail=_F6A222E6-ECA7-4E81-91CD-C82F4A5325DE"; protocol="application/pgp-signature"; micalg=pgp-sha256 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.40.0.2.32\)) Date: Mon, 21 Dec 2020 20:02:18 -0600 In-Reply-To: Cc: tyson andre , "internals@lists.php.net" To: Mike Schinkel References: <94748D59-630B-4EE2-8106-B68AA4E449D2@benramsey.com> 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=_F6A222E6-ECA7-4E81-91CD-C82F4A5325DE Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Dec 21, 2020, at 16:15, Mike Schinkel wrote: >=20 >> On Dec 20, 2020, at 9:09 PM, Ben Ramsey wrote: >>=20 >>> 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. >>=20 >> 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. >>=20 >> For example, with >>=20 >> $a =3D ['foo', 'bar', 'baz=E2=80=99]; >>=20 >> `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. >>=20 >> But now, if we do >>=20 >> $b =3D array_merge($a, ['qux', 'quux']); >>=20 >> `$b` is now back to being a list, so `is_list($b)` returns `true`. >>=20 >> 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=99t >> 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. >>=20 >> Cheers, >> Ben >>=20 >=20 > Would either is_zero_based() or is_zero_indexed() be a reasonable > name instead? >=20 > -Mike >=20 > P.S. See https://en.wikipedia.org/wiki/Zero-based_numbering I don=E2=80=99t think changing the name changes my concern, but as Tyson pointed out: > These idiosyncrasies of php and unintuitive behaviors existed prior > to this RFC. I=E2=80=99m generally +1 on this RFC, but as I think about it, maybe = there is a problem with the name. If we choose to introduce a pure list construct at some point, then `is_list()` may cause confusion (or maybe it = won=E2=80=99t, if it can be made to return `true` for a zero-indexed, standard PHP array *and* a `list`, whatever that might look like in the language). Cheers, Ben --Apple-Mail=_F6A222E6-ECA7-4E81-91CD-C82F4A5325DE 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+FTqgAKCRCwLZeYnIwH G3GkAP46LpB5ybh/IdUVJjK51bwsyTm9ExDkr7XWKEpmlX3lGQD+L+PZnjFxXOOX n0TuMVs1G0mmoGOPoXz2nDUsvrh/zkU= =SoQ4 -----END PGP SIGNATURE----- --Apple-Mail=_F6A222E6-ECA7-4E81-91CD-C82F4A5325DE--