Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112578 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 18616 invoked from network); 21 Dec 2020 22:42:50 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Dec 2020 22:42:50 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E33D71804E4 for ; Mon, 21 Dec 2020 14:15:20 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,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-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) (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 14:15:20 -0800 (PST) Received: by mail-qv1-f50.google.com with SMTP id az16so5169197qvb.5 for ; Mon, 21 Dec 2020 14:15:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=IaWb5X/pk4/39pRTBK6gIJpNzr1yAKxZAhw53yQC2Og=; b=sCeEw0I7l3gcLoPTbWEiVDpbX2wt8OnyMeHZszvdTziJQaq4uRE4jSo8/fdu0Zo8Zs nd0GE7wks6tGORVzxT9Gwjgasd147u6scXBHwyL5/07CGlqe/rCWdcPkzCGLtphimj2K /pGNf42w+pBeEAC7TRoLKk+wE7++61I2c5ekXha0ENaP1TzBDisEnNshCvwn7b1VLJ5x ef/n8y68pdo/y6dk9dpfMdgBnqsi1xrSwBvzTepExIA6Y7TZ84hjvdnVMI5zHBwIHTSB s83H4roN9k2tGqCkmzdVzeDUsBVvJWEvtl7hOJWjrkSfRvZxIyuE5UXhYWX9/zKVBOs5 2sQA== 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=IaWb5X/pk4/39pRTBK6gIJpNzr1yAKxZAhw53yQC2Og=; b=mwP6M4TIct/628VM3gzti4tO+0kukDgRE9sWZ/6dANYDjguTWS3t+jAsU/sfLMrCfk KWMXUz2yD1Ihn9UnCQkVT1+gzA9AnSv//T1DTKh32ljvWTRxpxIsQXTkJ7vZjddTOwWU SVcLJkuedtavDbqMwiltSKZoF18rWSh8y0jDRfUMhHMuYsmhFEdjIYR8MXbwpjQBfls9 e11VAVdUBrvv2rTXYOD5x15hpYs69bNtmkEke2XSw+N/5K+8orkvdPEXFjE81gmc65pB WmOqEwWLc5e9LWhhBf07rGu3Ix8CFdE6+CQ+47CTgo92/HPBkKnLCMmatnKEzmjTMlsK nN7A== X-Gm-Message-State: AOAM531kDudfBHQnLUYWiQk1+CfDSpF4jBedrLS+Hz4xdw2Ut6h4MeIn gdYYasgrjVGmBdiYQ9IeG11XjQ== X-Google-Smtp-Source: ABdhPJyTPwCpsDaPaArH3ktKf/FqEi7DHvMjIeCHgZ807RBKo+E5vBaIBurKojJqg/1xQjUui853Gw== X-Received: by 2002:ad4:4c44:: with SMTP id cs4mr19155727qvb.25.1608588918150; Mon, 21 Dec 2020 14:15:18 -0800 (PST) Received: from [192.168.1.236] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id b4sm10835817qtb.33.2020.12.21.14.15.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Dec 2020 14:15:17 -0800 (PST) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_CDA5DCC2-590F-4E8A-A269-C979FF502103" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Date: Mon, 21 Dec 2020 17:15:16 -0500 In-Reply-To: <94748D59-630B-4EE2-8106-B68AA4E449D2@benramsey.com> Cc: "internals@lists.php.net" , Ben Ramsey To: tyson andre References: <94748D59-630B-4EE2-8106-B68AA4E449D2@benramsey.com> X-Mailer: Apple Mail (2.3608.120.23.2.4) Subject: Re: [PHP-DEV] [RFC] Add is_list(mixed $value): bool to check for list-like arrays From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_CDA5DCC2-590F-4E8A-A269-C979FF502103 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > 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 Would either is_zero_based() or is_zero_indexed() be a reasonable name = instead? -Mike P.S. See https://en.wikipedia.org/wiki/Zero-based_numbering = --Apple-Mail=_CDA5DCC2-590F-4E8A-A269-C979FF502103--