Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108402 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 23011 invoked from network); 4 Feb 2020 23:06:56 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Feb 2020 23:06:56 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B93131804F2 for ; Tue, 4 Feb 2020 13:19:10 -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 out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (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 13:19:09 -0800 (PST) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 38E762212F for ; Tue, 4 Feb 2020 16:19:09 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Tue, 04 Feb 2020 16:19:09 -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=UQ9K+0 hUSNioe3d/ZppC+jn90MU7uXOl5REYOZsQw8k=; b=pCEuFJg9cqOAItP+xctOA4 mIoHWjSkJJCuoylU9G81YuvZ/hEE8ybSCW92LVjbnC6sZYz96Ih8s+NLK5VxSBP3 eDM/ERMpeGnV5KtPc3nkLOdffPwdBgfIDeYis/RtSEIqaufjLbr3da5BdB+jTyIj mcF2ya+znso5S0+PeqBEUKeT676awb5rn54aksCT86aIvqfvwnto5ZnoJ2omzZrd ANWKjQ39tCt8rVmkL6xIK0S14IzzmPJXwgOIpJn+0R9TgVBnOa6wDLHD9QKf2OmP QnOr+t8LnPTqhs3i39eRiqT9do1gzDPHP6PHrtCfhnwV2vdZtoOAtbCZZpxMyGYg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrgeelgddugeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucffohhmrghinhepphhhphdrnhgvthenucevlhhushhtvghrufhiiigvpedtnecu rfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id B4A3514200A2; Tue, 4 Feb 2020 16:19:08 -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: In-Reply-To: <2f37a761-9a54-b8b6-3bcb-39cf2224c227@aimeos.com> References: <861afae0-4568-745f-6615-a252067cc506@aimeos.com> <5f5a4ab3-e609-4324-b056-53f782f1a63b@www.fastmail.com> <2f37a761-9a54-b8b6-3bcb-39cf2224c227@aimeos.com> Date: Tue, 04 Feb 2020 15:18:47 -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 12:40 PM, Aimeos | Norbert Sendetzky wrote: > Am 04.02.20 um 19:17 schrieb Rowan Tommins: > > I think Larry's point was that the flexibility of PHP's array type makes it > > really hard to pin down whether a given object is "array-like" or not, and > > which attributes a particular function actually cares about. > > What else besides array access, counting and traversing is possible that > may differ from classes that implement those interfaces? > > > A general "intersection type" system might be more useful, because then you > > could require the parts you specifically needed, such as > > "traversable&ArrayAccess" or "traversable&countable". > > I think that's too complicated and we should make it as easy as possible > for PHP developers. > > Also, there's already an RFC for intersection types but it was never > adopted: https://wiki.php.net/rfc/intersection_types Rowan is exactly right and said it better than I did. The point is that "I can count() it", "I can foreach() it" and "I can bracket it" are three different things; in practice, a given function likely only cares about one, maybe two of those at a time. Adding a type for "an object that mimics all of the dumb things arrays do, but now passes differently" doesn't strike me as useful; it strikes me as the sort of thing I'd reject in a code review if someone tried to do it in user space. The problem with PHP arrays is that they're not arrays; they're a hash map with poor safety, lame error semantics, and some cheats to make them kinda sorta look like arrays if you don't look too carefully. In practice, they create more bugs than they fix. Intersection types would be absolutely delightful and I want them for numerous reasons. --Larry Garfield