Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107818 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 43764 invoked from network); 18 Nov 2019 11:01:50 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 18 Nov 2019 11:01:50 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 509D72C43CF for ; Mon, 18 Nov 2019 00:54:22 -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=0.0 required=5.0 tests=BAYES_20,FROM_EXCESS_BASE64, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS14618 54.204.0.0/15 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) Received: from smtpbguseast2.qq.com (smtpbguseast2.qq.com [54.204.34.130]) (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 ; Mon, 18 Nov 2019 00:54:21 -0800 (PST) X-QQ-mid:Yeas17t1574067245t505t41438 Received: from 90373548D78A4F9A84016F99F658592A (me@jhdxr.com [155.69.179.10]) X-QQ-SSF:00000000000000F0F61000000000000 To: "'Aimeos | Norbert Sendetzky'" , References: <461958fe-182e-59bf-9fdb-b110fd09e2b2@aimeos.com> In-Reply-To: <461958fe-182e-59bf-9fdb-b110fd09e2b2@aimeos.com> Date: Mon, 18 Nov 2019 16:54:03 +0800 Message-ID: <003201d59ded$ba7d6e10$2f784a30$@jhdxr.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQKXF9FyiXdqhoi07BzwbshOSG+70qYNqLCw Content-Language: en-us X-QQ-SENDSIZE: 520 Feedback-ID: Yeas:jhdxr.com:qybgforeign:qybgforeign7 X-QQ-Bgrelay: 1 X-Envelope-From: Subject: RE: [PHP-DEV] Concept: "arrayable" pseudo type and \Arrayable interface From: me@jhdxr.com (=?utf-8?b?Q0hVIFpoYW93ZWk=?=) The union types RFC passed, so I didn't see much value in the arrayable = pseudo except pressing less keys.=20 Regarding the Arrayable interface, or toArray method. Since it extends = Iterator, iterator_to_array can do the job already.=20 So what's the benfits for introducing this new interface?=20 I would suggest to find a way to make those built-in array_* functions = support the arraylike objects, no matter which interface it requires, = existing ArrayAccess, or any new interface. Regards, CHU Zhaowei > -----Original Message----- > From: Aimeos | Norbert Sendetzky > Sent: Sunday, November 17, 2019 10:41 PM > To: internals@lists.php.net > Subject: [PHP-DEV] Concept: "arrayable" pseudo type and \Arrayable > interface >=20 > Since PHP 7.1 there's the "iterable" pseudo type hint that matches = "array" > and "Traversable". >=20 > PHP frameworks would profit from support of an "arrayable" pseudo type > hint that matches "array" and all objects that implements = "Traversable", > "ArrayAccess" and "Countable". >=20 > Thus, we could pass arrays or all objects that behave like arrays to = methods > and do: >=20 > function useArrayable( arrayable $arg ) : arrayable { > $cnt =3D count( $arg ); > $value =3D $arg['key']; > foreach( $arg as $key =3D> $entry ) { ... } > return $arg; > } >=20 > It would be useful to implement an Arrayable interface too: >=20 > interface Arrayable extends \Iterator, \Countable, \ArrayAccess { > public function toArray() : array; > } >=20 > Then, we can use array like objects: >=20 > class Test implements \Arrayable > { > // ... > } >=20 > $arrayable =3D new Test(); > $arrayable['key'] =3D $value; > $arrayable =3D useArrayable( $arrayable ); >=20 > And if necessary, we can convert them to native arrays: >=20 > if( $arrayable instanceof \Arrayable ) { > $arrayable =3D $arrayable->toArray(); > } >=20 > -- > PHP Internals - PHP Runtime Development Mailing List To unsubscribe, = visit: > http://www.php.net/unsub.php >=20