Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101663 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56260 invoked from network); 25 Jan 2018 14:52:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Jan 2018 14:52:41 -0000 Authentication-Results: pb1.pair.com header.from=derick@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=derick@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 82.113.146.227 as permitted sender) X-PHP-List-Original-Sender: derick@php.net X-Host-Fingerprint: 82.113.146.227 xdebug.org Received: from [82.113.146.227] ([82.113.146.227:43082] helo=xdebug.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9B/91-37264-53FE96A5 for ; Thu, 25 Jan 2018 09:52:37 -0500 Received: from localhost (localhost [IPv6:::1]) by xdebug.org (Postfix) with ESMTPS id 92238DE39C; Thu, 25 Jan 2018 14:52:34 +0000 (GMT) Date: Thu, 25 Jan 2018 14:52:33 +0000 (GMT) X-X-Sender: derick@singlemalt.home.derickrethans.nl To: Michael Morris cc: PHP internals In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Subject: Re: [PHP-DEV][RFC][DISCUSSION] Collection Inspection From: derick@php.net (Derick Rethans) On Wed, 24 Jan 2018, Michael Morris wrote: > Ok, here's another idea I've been mulling over. This I know is possible > because I've done it using user land code, specifically Drupal 8's > Assertion\Inspector class. > > https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Assertion%21Inspector.php/class/Inspector/8.5.x > > These methods provide a means to inspect collections - arrays usually but > also Traversables. They fill a hole in the PHP library - the ability to > check collection integrity. IMO, it makes a lot more sense to check integrity when creating the "array" structure. Instead, I would suggest to add a native Collection type, that takes a "type" as argument. They aren't quite full generics, but it does 1. fix something; 2. isn't really complicated. What I am suggesting is to add a new syntax "Collection<$type>", mimicking a class, but having a type as "argument": $a = new Collection; And then $a can act as if you'd use an ArrayAccess'ed class. Upon each set or update, the type of the value can then be checked against the type. Consequently, this would also mean you can type hint on Collection instead of for example an earlier suggested array of type, where upon passing in the array each member was checked for its type (slow). And on top of this, this could be extended to do proper generics too. cheers, Derick -- https://derickrethans.nl | https://xdebug.org | https://dram.io Like Xdebug? Consider a donation: https://xdebug.org/donate.php, or become my Patron: https://www.patreon.com/derickr twitter: @derickr and @xdebug