Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107810 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 65252 invoked from network); 17 Nov 2019 20:13:35 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 17 Nov 2019 20:13:35 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 6A4BE2D19C6 for ; Sun, 17 Nov 2019 10:06:01 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Sun, 17 Nov 2019 10:06:00 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id q70so14983736wme.1 for ; Sun, 17 Nov 2019 10:06:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=ybDnLu+tluhWt3ya6UEwiNkh+oKDVt1JNpBllTddE6M=; b=TQ3X1ZcIdFMUsjz9E4w92PWy6x79dmZleBDeXF4ZiGKr+spuUXbSGGnk0FEevzfFwJ 2eHwgrtGCA6lAOfOV31HoWLzgopS37SGfaOIKo5eV1Sc2W9iHIyjv3vqyTyQMJLCC+AS ZXtSUjTo5FZT5gn5Av8iggb0l4FLag77/mEOHoQpp0DISIVLuhQ8akdCYHAZiMxqfpMV kVNNZNF7H2oNNUWVoQ1TsYdB8DkMH4MelllRTt/7nNbeXWoActs/spwb/E34fCirXtNE axVW9BHxKmeRdLpM9SbarKyoaOcDT+GZrtg7pwzd3yzGL2PxKNh0CB5+kYIXy8AWbxdU mqkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=ybDnLu+tluhWt3ya6UEwiNkh+oKDVt1JNpBllTddE6M=; b=LRlacmRi1hvK4isMFQ+j3oZ8d4u4mAQPllO0f0N6QgFTLd8+iRItZKhEf//1ndQ1ov oejSHP1ocm3Nob1K25XmvJ0m2ibPNjtd7GFQe3fWUMutIEW1ncIJ4jZxzGHS7AEoIldB bzgkndKPDaoCcrGCRK30kz5PVYe7e6iMzUhdOG3E1kUC3orCD37HytD+p6xMS2IO3lBf wIP/fz6eqKsXKOkn8G4BXntkZ0NtsF/rrETWS1xTkCLGSE7FtgsuZS9tTP5R6Io68lW4 WN3pcs1Wf9W2wWNLuWcBYgUpM+OrnPg+N292oki3uDb9TivNmToX0osjDbBAdmtci94N g7TQ== X-Gm-Message-State: APjAAAX5/5UE6+PqG8BxQ1Xk6wqxnoVP608Ud8Y4YFvnd3+c6sjpM5Cr f7lUmeOcBYTEnkJgf9b46O7uexkh X-Google-Smtp-Source: APXvYqyaivbc0Pv9AYGt/NxKNVZ3ZG7sOEaK7Zl2+d3IhBdK5/ov+pfyX8PZc2cnJHqYSn90hj21Dg== X-Received: by 2002:a7b:cb86:: with SMTP id m6mr27143045wmi.124.1574013958400; Sun, 17 Nov 2019 10:05:58 -0800 (PST) Received: from [192.168.0.14] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.googlemail.com with ESMTPSA id m13sm17360393wmc.41.2019.11.17.10.05.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 17 Nov 2019 10:05:57 -0800 (PST) To: internals@lists.php.net References: <461958fe-182e-59bf-9fdb-b110fd09e2b2@aimeos.com> Message-ID: Date: Sun, 17 Nov 2019 18:05:56 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 MIME-Version: 1.0 In-Reply-To: <461958fe-182e-59bf-9fdb-b110fd09e2b2@aimeos.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB X-Envelope-From: Subject: Re: [PHP-DEV] Concept: "arrayable" pseudo type and \Arrayable interface From: rowan.collins@gmail.com (Rowan Tommins) On 17/11/2019 14:41, Aimeos | Norbert Sendetzky wrote: > PHP frameworks would profit from support of an "arrayable" pseudo type > hint that matches "array" and all objects that implements "Traversable", > "ArrayAccess" and "Countable". ... > It would be useful to implement an Arrayable interface too: > > interface Arrayable extends \Iterator, \Countable, \ArrayAccess > { > public function toArray() : array; > } It feels like there are two alternative suggestions here. Not only do they use the same keyword to mean different things, but "convertible to array", and "usable as array" seem like distinct concepts to me. For the "convertible to array" case, I think __toArray, or an interface specifying just that one method, would make more sense than combining it with the existing interfaces. I'm sceptical of that concept, though, because most objects could be converted to many different arrays in different circumstances, each of which should be given a different and descriptive name. For the "usable as array" case, the big advantage would come if internal array_* functions could take such objects, but that requires a bit of thought on how each function should behave. There could also be some surprising behaviour passing infinite iterators, or objects where the output of ArrayAccess and iteration don't match up. It might make sense to have objects opt into an Arrayable interface, to make clear they're expecting to be used this way; but require no additional methods other than those required by Iterator (or Traversable), Countable, and ArrayAccess. Regards, -- Rowan Tommins (né Collins) [IMSoP]