Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112584 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 35287 invoked from network); 22 Dec 2020 01:32:47 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Dec 2020 01:32:47 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A6AB41804DD for ; Mon, 21 Dec 2020 17:05: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=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 NAM04-SN1-obe.outbound.protection.outlook.com (mail-oln040092011011.outbound.protection.outlook.com [40.92.11.11]) (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 ; Mon, 21 Dec 2020 17:05:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FC8m7wj4ppBPYnR7N4xk9tnTxi7WxscQeWiqxcGLFE+zq1BLM7MQMImdjfe99GpELeFAMmypHtMRGZ2xfl2vRLud79sXwCaLCJOI+f8Uk0m29HmtSRakvZszmwduQY//JgC1UcYVx4BNdQEurCGKWNbm3y71VAN4RdXWKoBt7kJErlvVX25akMgWRirY5vUiDFrmpNvofxZ098bDSpx4HFbaVa2QlStN5iW8KnhMLjNICbW5XysuHFp7QxNN4bleVY0qaRchUWg1qjdfQnUKK/Nhr8qKWkYpNe5cWfVk21FMBwUPXreMQBJN3d3mgPJ9W23lRveO0aI2A6I6mupcsQ== 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=pW6XuLYIN5Fe/Fe9O/F2QCwzN7Sm7pEuuYVISedmMWM=; b=hQTZIh6gUuF+8qx9HsCQXM6VOtV5+ALvYpPQbQfwF40br2sGAC1k3E97CV2mdALgsXxjSKJgwePBidZLbbtmhcEaD1o+m5YLVfbO4b8ysjj5uQNfIVw9ltDPpaT92AtVzvtywMHSjDlqzOto0RovP50bqnQ/azW0TW08RIi3Dv9exRjSFbMKCwcJUUdnt1IxY2lPFpEnJSQtUrvA6TjvRigpRLgdF2tAvUWeTcpVVMdgT+QakyB4V/FikA+RXOelYGoYk5D6vQLLal2H1Pm4RF8LY94AmT1sFkI57Tmu3gCRJrnfUW7BaPY5j3Qo0X1WL5y+Cj+85m7x0VCxwflQOg== 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=pW6XuLYIN5Fe/Fe9O/F2QCwzN7Sm7pEuuYVISedmMWM=; b=Z5z6dpMKipF3AZmqJOcnhh4nI8/Vx74AXL7t2WenwEWBL5VEFB3nqfYg4bEHyMfJiYKc9QVqUlEQgmBk+p1nTWclYPziOVcRlO29BuxJSoswbctg2+CR6U0KDjxUJfmGxpRqqWzHIh9CNowGFbd2o5p68galCzqS0MSk/A0c7pHUUp687OFF4IpgqL3kB7XTtjjXa4nLCWbpOL+dcpYAUz/o2M4NSNnZSerLslbVW/VU/X/mQNOQ9x12f0zMkb14lsNS5q9gBchlg6w/2VZ+s6+3QDTXLnKW+jpfC5Zrymoa7VQFG2zONAII3azS7fzv6MWR7hauLuP8DdhavU7jHA== Received: from CO1NAM04FT009.eop-NAM04.prod.protection.outlook.com (10.152.90.56) by CO1NAM04HT196.eop-NAM04.prod.protection.outlook.com (10.152.90.230) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3676.25; Tue, 22 Dec 2020 01:05:20 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:7e4d::51) by CO1NAM04FT009.mail.protection.outlook.com (2a01:111:e400:7e4d::137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3676.25 via Frontend Transport; Tue, 22 Dec 2020 01:05:19 +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.033; Tue, 22 Dec 2020 01:05:19 +0000 To: Ben Ramsey CC: "internals@lists.php.net" Thread-Topic: [PHP-DEV] [RFC] Add is_list(mixed $value): bool to check for list-like arrays Thread-Index: AQHW1/yQAfO4kGRR2k2eJYkm1Vx5xg== Date: Tue, 22 Dec 2020 01:05:19 +0000 Message-ID: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:A27D51CB2F7A7D476ADE6C374ED88FCEE1B6939065D4CC19595C8681E02649E1;UpperCasedChecksum:F84528855D360DBA74AD22A59A69778A56D354D04BEAF20E2669BA5047D3B752;SizeAsReceived:6920;Count:42 x-tmn: [hhdPDNJ5++lxOVto+cy2udaqTlXht7sTB2O32A4FYgdqlsEOxUiPotQU4D/u4fuU] x-ms-publictraffictype: Email x-incomingheadercount: 42 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: d4b47652-7e54-4e8e-298e-08d8a615a6fb x-ms-traffictypediagnostic: CO1NAM04HT196: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: GHr+n94cG5tY4FIE3GyTw02WlOi9e88d3kU8G2M0Jp81kC/mA50wyc/y34hiVkc3cRN+XA3pnFFzkRYwhNjQQxsM+HAP80YtJ4Nq1CFg7xV+FEVOtyKogAV7qqY388BhBq+PLNAgqHFfRGH30UGjb43f1qMeISBftucGzYUYi7rPqj07NWl05avfcP1eNKwjz2Kpsg2Sst0VJbe0+9ZDNIZFDtLBYMlOCZKWsN7sH/eyYhV0he+AL23asvcpQvln x-ms-exchange-antispam-messagedata: a8o8NkVJR1RRtOn8CSwaZmQTKTd1/PbbFIX//q2Rm3DeA+LVfqcyO0Zo3hwJIa7KP2TGYTOv6oH0xyB+xiO0nJgwRIUyOdcyrb0vNw5bWgJpbiZ7++mtoByhwlmosteOrlgTWR8jeBcGm+2DYL6XZLN2BDRMqgKrQjHUwf1LbNI5rinJpfaaLXcwnVl2YkU/GkHjDGK9ofr5PKwIpVTZIg== 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: CO1NAM04FT009.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: d4b47652-7e54-4e8e-298e-08d8a615a6fb X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Dec 2020 01:05:19.8417 (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: CO1NAM04HT196 Subject: Re: [PHP-DEV] [RFC] Add is_list(mixed $value): bool to check for list-like arrays From: tysonandre775@hotmail.com (tyson andre) Hi Ben,=0A= =0A= > I think there are some places where `is_list()` could be unintuitive to= =0A= > those who don=92t understand some of the idiosyncrasies of PHP.=0A= > =0A= > For example, with=0A= > =0A= > =A0=A0=A0 $a =3D ['foo', 'bar', 'baz=92];=0A= > =0A= > `is_list()` will return `true`, but if you run `$a` through `asort()`,=0A= > `is_list()` will return `false` because the keys are no longer=0A= > consecutive integers, but is there any doubt this is still a list?=0A= > Maybe in a pure sense, it=92s not, but I think this could be confusing.= =0A= > =0A= > But now, if we do=0A= > =0A= > =A0=A0=A0 $b =3D array_merge($a, ['qux', 'quux']);=0A= > =0A= > `$b` is now back to being a list, so `is_list($b)` returns `true`.=0A= =0A= Yes, that's correct.=0A= These idiosyncrasies of php and unintuitive behaviors existed=0A= prior to this RFC.=0A= =0A= It's also confusing when `reset($x)` is not the same thing as `$x[0]`=0A= on a non-empty array with keys 0..n-1 out of order if you're still learning= php.=0A= =0A= > While I understand the convenience `is_list()` provides--I myself have=0A= > implemented the opposite of this numerous times (e.g.,=0A= > `is_dict()`)--it comes close to implying a data type that PHP doesn=92t= =0A= > have, and I think this could give a false sense of type-safety-ness=0A= > when using this function to check whether something is a 0-indexed=0A= > array.=0A= =0A= It would simplify `is_dict(array $x)` to `count($arr) > 0 && !is_list($arr)= `,=0A= and potentially improve performance.=0A= =0A= There's already some ways `is_*` doesn't correspond to a data type=0A= =0A= - `is_numeric` does not correspond to a data type.=0A= - `is_callable` varies depending on the context where it's called for priva= te methods.=0A= - `is_resource` returns false if a resource is closed.=0A= - `is_file` is checking for a path (and readability?) on disk, not a type.= =0A= =0A= If you do understand what the type checks are doing, it makes it easier to = check type-safety-ness=0A= in a script (e.g. `if(!is_list(...)){ /*warn*/ }` in a standalone script) o= r with external analyzers.=0A= =0A= Thanks,=0A= Tyson=0A=