Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107853 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 33744 invoked from network); 24 Nov 2019 14:58:55 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 24 Nov 2019 14:58:55 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 9F0812CFDDF for ; Sun, 24 Nov 2019 04:53:04 -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=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS34788 85.13.163.0/24 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) Received: from dd46610.kasserver.com (dd46610.kasserver.com [85.13.163.220]) (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, 24 Nov 2019 04:53:04 -0800 (PST) Received: from [192.168.178.20] (x4d0a6f33.dyn.telefonica.de [77.10.111.51]) by dd46610.kasserver.com (Postfix) with ESMTPSA id 426DB434074E for ; Sun, 24 Nov 2019 13:53:03 +0100 (CET) To: internals@lists.php.net References: <861afae0-4568-745f-6615-a252067cc506@aimeos.com> Organization: Aimeos GmbH Message-ID: Date: Sun, 24 Nov 2019 13:53:02 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <861afae0-4568-745f-6615-a252067cc506@aimeos.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Envelope-From: Subject: Re: [PHP-DEV] [RFC] "arrayable" pseudo type hint From: norbert@aimeos.com (Aimeos | Norbert Sendetzky) > Since PHP 7.1, there's the "iterable" pseudo type hint that matches > "array" or "Traversable". > > PHP frameworks would profit from support of an "arrayable" pseudo type > hint that matches "array" and all objects that can be used like arrays. > > For that, "arrayable" objects have to implement these interfaces: > - ArrayAccess > - Countable > - Traversable (i.e. either Iterator or IteratorAggregate) > > > Implementing "arrayable" pseudo type, we could pass arrays or all > objects that can be used like arrays to methods and do: > > function useArrayable( arrayable $arg ) : arrayable { > $cnt = count( $arg ); > $value = $arg['key']; > foreach( $arg as $key => $entry ); > return $arg; > } Implementation is pretty straight forward: https://github.com/aimeos/php-src/commit/8c4f7f1142e20696b9481f4329928a6140eb05fd It also contains is_arrayable() and ReflectionClass::isArrayable() methods. Tests haven't been implemented yet.