Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101664 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62778 invoked from network); 25 Jan 2018 16:13:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Jan 2018 16:13:44 -0000 Authentication-Results: pb1.pair.com header.from=derokorian@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=derokorian@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.174 as permitted sender) X-PHP-List-Original-Sender: derokorian@gmail.com X-Host-Fingerprint: 209.85.216.174 mail-qt0-f174.google.com Received: from [209.85.216.174] ([209.85.216.174:37220] helo=mail-qt0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BA/30-61119-5320A6A5 for ; Thu, 25 Jan 2018 11:13:42 -0500 Received: by mail-qt0-f174.google.com with SMTP id d54so20518150qtd.4 for ; Thu, 25 Jan 2018 08:13:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=EMMZl+3Jb7AloY94kVwOF957vylNH64b210pvxfDE2w=; b=QCNYMkg+hdEZOAQWkDGHS04xr9iUkIZeZRszKA/CQuQNYA1C7BZDmHmRX7nMAsvBZH MFgE5CF18f6JuWGHbxUl5GVwz19qrMOYWQQyyJYkzfL6yPp6WdPsk48aXyJ0QvOJxzZZ tlWL5tL4yzL9xWEQxhy9thOzeWP6XHTCK0aWoHJzzSal8rwkmbh5iyiFq3g1onSyXERe F+q3k5cvZbsrENi8hYwAzMF4nMKHUuVP2ou1U4eSCZDD/7VD2QamVHZCqInMZMFUuEbV 8mtNzOnDO85mh7X2rb9F42pnsd++3Xwck1jhT7DwrkNHfyq2o8CcnxxDHdGtvHuQWqiq KY+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=EMMZl+3Jb7AloY94kVwOF957vylNH64b210pvxfDE2w=; b=pqpFjV9clLoWuWLtGzWdTqy0uIIf/Fo3AmmLup2Qh1LwQ1rG08o2XCvuNbUKOsfG7e mReM6lHJi7zWYOYL9JziQFBVjAsxfVay65vjMkDwq7BHXBPLDlzgHBheSI4NvqlwG9Vg +xfcoN0JiyuHGRj/DiIDpGo4slp0yjOckJ03nfYfH32HrxM/iPr8AHaFNLYfnFJ/0XQ1 29qbUU5B/nKwKJueSVAjnjWmfOwoR+ulx7TiVvXWBYay83Wt7D4z0YTiJmUA4jlc00eJ wAgt7QCIQ5ezRxgKykO7vTzDNmuG++dbTYLiZr6H9819cEcEGspQR28NCwPkIoDwNwyM Z3wQ== X-Gm-Message-State: AKwxytfo5/smuBFvl74FeKly2DnSwlc0CuVstNBbZVO6F1TMRl+Vv0ZV S5zdpTnOnubxmN952opUxxVguNZe70QK32gNqA== X-Google-Smtp-Source: AH8x227sEOCSSpHPthTTFygMhhqmxxgGRHkgStPTsik5bhMJ4BcOaGt4MKTIN+jh6fm8CKzl7LP7XKqQsz5lBEyGG8w= X-Received: by 10.200.56.19 with SMTP id q19mr17434158qtb.313.1516896819522; Thu, 25 Jan 2018 08:13:39 -0800 (PST) MIME-Version: 1.0 Received: by 10.200.37.119 with HTTP; Thu, 25 Jan 2018 08:13:39 -0800 (PST) In-Reply-To: References: Date: Thu, 25 Jan 2018 09:13:39 -0700 Message-ID: To: Derick Rethans Cc: Michael Morris , PHP internals Content-Type: multipart/alternative; boundary="001a11378c1016b0dd05639c10fd" Subject: Re: [PHP-DEV][RFC][DISCUSSION] Collection Inspection From: derokorian@gmail.com (Ryan Pallas) --001a11378c1016b0dd05639c10fd Content-Type: text/plain; charset="UTF-8" On Thu, Jan 25, 2018 at 7:52 AM, Derick Rethans wrote: > 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": > > Just like to point out if it's considered a class, or takes the same space there is likely collisions. While most collection classes on github look to be in a namespace, there are lots that aren't. Of course github only gives us a view of open source projects that happen to be on github. > $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 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --001a11378c1016b0dd05639c10fd--