Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108397 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 60096 invoked from network); 4 Feb 2020 19:06:34 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Feb 2020 19:06:34 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9CCE41804F2 for ; Tue, 4 Feb 2020 09:18:46 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (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 ; Tue, 4 Feb 2020 09:18:45 -0800 (PST) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 8CD7521AA4 for ; Tue, 4 Feb 2020 12:18:44 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Tue, 04 Feb 2020 12:18:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=/eWsm9 D/BCXamTdipzPKEMFwujbH6V5SV1U9jsMQ7ck=; b=FU/xt8HYlXaW/d9W/pEmMX U0Kx3CfIZUeXwptNfyC9VzGfokczzlMl88iGEcJI+p8d0oZyjtfWOkjG9fOtmy3L KdSGKhWZBxsNaXX9YnGJiCvMTpjRUUaHH4BLE/RgLTgGNEw7wXF+Wgu+ZN7MmLX8 ARkWK0bQasbW5Ggc13Gemzek/X8T2a4khfRsWVmK7c0Wo66dUI7EQZQ1ZJAWVW3R BwV4QnojMuDrM5LbLa/1/UzWP60qoRN5lRkb9kILtQEERBO6f/J6mdUtvWuxQPvF TKefVCY/X3eM1a44usJkDxJ+j26Yzzymyb+bV0dOb7PAagPOtdmxHjDORpwLGdLQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrgeelgdelgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgrrhhr hicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh eqnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgr rhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 4E7F714200A2; Tue, 4 Feb 2020 12:18:43 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.1.7-802-g7a41c81-fmstable-20200203v1 Mime-Version: 1.0 Message-ID: <5f5a4ab3-e609-4324-b056-53f782f1a63b@www.fastmail.com> In-Reply-To: References: <861afae0-4568-745f-6615-a252067cc506@aimeos.com> Date: Tue, 04 Feb 2020 11:18:22 -0600 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] Re: [RFC] "arrayable" pseudo type hint From: larry@garfieldtech.com ("Larry Garfield") On Tue, Feb 4, 2020, at 6:48 AM, Aimeos | Norbert Sendetzky wrote: > I would like to modify my initial concept of an "arrayable" type because > PHP core developers seems to be in favor of the upcoming union data > types instead of adding a new "arrayable" pseudo type similar to "iterable". > > So, I would like to propose an "Arrayable" interface that combines > ArrayAccess, Countable and Traversable interfaces and adds a toArray() > method: > > interface Arrayable extends ArrayAccess, Countable, Traversable > { > public function toArray() : array; > } > > Then, methods signatures can support array and Array-like objects: > > function useArrayable( array|Arrayable $arg ) : array|Arrayable { > $cnt = count( $arg ); > $value = $arg['key']; > foreach( $arg as $key => $entry ); > is_object( $arg ) { $nativeArray = $arg->toArray(); } > return $arg; > } > > Adding a toArray() method also avoids controversy around using a magic > __toArray() method, even if this would be easier for developers in this > case. > > If union data types are available and "iterable" is implemented as > alias, an alias "arrayable" for "array|Arrayable" may be added as well. The more I think on it, the less I like `arrayable`. PHP arrays are a terrible data structure from a type system point of view, with too much functionality crammed into one variable type. If you want an object that shoves all the various bits of arrayness into one object, there's already ArrayObject, which you can extend if desired. Especially with union types, amalgam built in types like this are even less needed. Aside from iterable, the only other built-in alias I would see is one for array|ArrayAccess. But... it's now possible to do exactly like that, so I don't know how useful it would be. --Larry Garfield