Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108403 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 36600 invoked from network); 5 Feb 2020 00:12:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Feb 2020 00:12:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CFF511804DA for ; Tue, 4 Feb 2020 14:24:53 -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_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (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 ; Tue, 4 Feb 2020 14:24:53 -0800 (PST) Received: by mail-qt1-f182.google.com with SMTP id h12so16848qtu.1 for ; Tue, 04 Feb 2020 14:24:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=dXoWy9ifd9X2AAAQhq6othFwsfj7q4Wvx2AhMKzA9O0=; b=tE4m57kNkc5ifCtoq/xKUd/icniLp5NFyHeHWuPVhrgr+e6npMriQSB549FhtY0gTd FQlAsXn63OdU9CyOiIJHkABtbYfBDmy5A6HghdCo4GSkekBpSC0NnXKKm7xScG6xPybd ZTDgUdv8WYZ93x+BHPzrzA9dF81F+APJDOjRurGtWPDaQCTSElbc2u9oEp3M0utckl6n gctoGNLoPH//uiT1LPX39Rhv/gY64/sPC4JRNHOkrAGdHa4/zCuAuTQwN1eOTbWRrt/E MV9S15l9IGkoYEnzv6rPru76WK+c0zdpJavLKBrlXmFiIzu1eYL+i6hE3t8E/sM5yH5t kUgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dXoWy9ifd9X2AAAQhq6othFwsfj7q4Wvx2AhMKzA9O0=; b=hxjyPJnDax5fJPThwA1dePYtV89E6bg760u0yhKpjWFsyvjFZiSe8H2bCcnx9Da7f4 v0jAQ5ZXdV9OI8BHVeT6ognez4YcLjSEJnYz4XOft2T7jLUwdPLX1SbhY217d5Rt5yRH AOJCyyvJ/qYj2RZgCiZAS+4S4Hn8R327jCJOiV75WKRCU/njHxWS2Iuc2+8+RYigK8CY 0SorWkRhKDHd71lSPcQinZcji95xfy8lJE1iYhvQkxswYt5dCL3I07ES7VUraI/cHmCU 79j+QKGGe6VQRU4AEVoHo0dZTeKhz3iO4mQecBZk3D9RQ0OPWyItzLjbntni/hZr2Uo8 TnXQ== X-Gm-Message-State: APjAAAXpBvZGty9k90NRVC8r3MbxkPjqrvWQO2c4c5CSoZJQei75lLBr lQznGqzSnMMiynKLKrExtgkPpShm/1U= X-Google-Smtp-Source: APXvYqzteCcZe5kNAWA25ftEXXw8yw4R2YNvzm5KbLNBJsfkjwcd4q9Wk/YGY8InfldvCJltII+PSA== X-Received: by 2002:aed:2d67:: with SMTP id h94mr30389426qtd.74.1580855088495; Tue, 04 Feb 2020 14:24:48 -0800 (PST) Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com. [209.85.222.181]) by smtp.googlemail.com with ESMTPSA id v2sm12762475qto.73.2020.02.04.14.24.47 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Feb 2020 14:24:47 -0800 (PST) Received: by mail-qk1-f181.google.com with SMTP id 21so19740235qky.4 for ; Tue, 04 Feb 2020 14:24:47 -0800 (PST) X-Received: by 2002:a05:620a:342:: with SMTP id t2mr29766202qkm.383.1580855087509; Tue, 04 Feb 2020 14:24:47 -0800 (PST) MIME-Version: 1.0 References: <861afae0-4568-745f-6615-a252067cc506@aimeos.com> <5f5a4ab3-e609-4324-b056-53f782f1a63b@www.fastmail.com> <2f37a761-9a54-b8b6-3bcb-39cf2224c227@aimeos.com> In-Reply-To: Date: Tue, 4 Feb 2020 23:24:36 +0100 X-Gmail-Original-Message-ID: Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000eeb53b059dc78157" Subject: Re: [PHP-DEV] Re: [RFC] "arrayable" pseudo type hint From: andreas@dqxtech.net (Andreas Hennings) --000000000000eeb53b059dc78157 Content-Type: text/plain; charset="UTF-8" On Tue, 4 Feb 2020 at 22:19, Larry Garfield wrote: > 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. > There is one good thing about arrays: They are passed along by-value by default, which gives them similar qualities as an "immutable" object. If you pass an array to a function as a parameter which is not by-reference, you can expect the original array to remain unchanged. (Objects or referenced variables within that array can still be modified of course) A function parameter which allows an object OR an array loses this advantage. If I have the choice between \stdClass and array for "unstructured tree of data", I will always prefer the array. ~~ Andreas > > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --000000000000eeb53b059dc78157--