Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101673 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84902 invoked from network); 25 Jan 2018 20:19:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Jan 2018 20:19:42 -0000 Authentication-Results: pb1.pair.com header.from=tendoaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tendoaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.180 as permitted sender) X-PHP-List-Original-Sender: tendoaki@gmail.com X-Host-Fingerprint: 209.85.213.180 mail-yb0-f180.google.com Received: from [209.85.213.180] ([209.85.213.180:43882] helo=mail-yb0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0C/E3-61119-DDB3A6A5 for ; Thu, 25 Jan 2018 15:19:42 -0500 Received: by mail-yb0-f180.google.com with SMTP id h9so3506129ybg.10 for ; Thu, 25 Jan 2018 12:19: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; bh=HgvottUX57zyC3lCilIVkTbRM25LSAGL73cTtxPDM8M=; b=aPsjkyBWJiEokpF+X0sp49GV5m4QwovpzT0T4vjzmDooeAbp0HdS0Xq5hWpmqswj6A 32CqB0D1f4Y4sfZc+Du8XzJ+mTPQgpfFJ5JkyJ4PUTBGanZn/KtpaVKJoEihTnBC0hI3 H8FJ6a0i/O2/tITRaZxvDuJMQCKJlGyxUCaLLlqtyWgfvAUb9khBgtmQdzVedLEjcuLX ePEJGm0hDaMTUeBhgXWcNFeHFQTlp7/2Y3k06GfAiKTbaWpgI4H1q6pXCPlk4/oTljyq ENVo7xHkT2OUQrG0R0S1CwxNe4kntcH7VHO0DrCP8ZBDOrpd/VKmuhU84D7TGpfSGgD0 cg3A== 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; bh=HgvottUX57zyC3lCilIVkTbRM25LSAGL73cTtxPDM8M=; b=tWP8wDCjzz0aku2OELSRHiOgx2OaCVV9jInADWDhfKH1/Oow7+SlIyT51Qxhqo5BVb gT9oiVao79ZBleSlz9nz+CIELEbHCUWSOmH4owGP8A5fDpW9vBCRaFWdfr28kEF5rMTr 1U5z2sMMek32Ln4P8AFRufZonJ6Gvq1CRegVqeqrkVm5EEBK4NXMPxZOsZUfkU4MY9Sa POLUQqVKr9MRhLhUwiMr+4Bb4wBGUpUT6+KBJtcgrRStohb1xGZFnfB1/233Qt/BOKZC DyQ/mD22TqQN53qiiMjIzmA57YVkzkNQCVJGEl4XyzMYkNXRt1FRR7fpsHd6sgsliGjy YhvA== X-Gm-Message-State: AKwxytdCQiAXT8nv2EXepBLIS+0dtot1xMBOJ6HoEl1M56gkFsKJp/kE pYTgzBeCr/OKJfgnamBZ/iwkz+H8NwyqYielV/0= X-Google-Smtp-Source: AH8x225RzYDsbbGLIiZxaIRLXXPrA8FwsL2utqxFlLLZMR9c+WKT53qQ9TP6beCbsboXCTfOyFB0D0goaeFJE02MfKo= X-Received: by 10.37.77.6 with SMTP id a6mr10390534ybb.410.1516911579199; Thu, 25 Jan 2018 12:19:39 -0800 (PST) MIME-Version: 1.0 Received: by 10.37.189.16 with HTTP; Thu, 25 Jan 2018 12:19:38 -0800 (PST) In-Reply-To: <9b12b0e2-185e-86fb-0e0b-c4f24bfbd661@gmail.com> References: <9b12b0e2-185e-86fb-0e0b-c4f24bfbd661@gmail.com> Date: Thu, 25 Jan 2018 14:19:38 -0600 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="001a113bddf4d57e2505639f7f0e" Subject: Re: [PHP-DEV][RFC][DISCUSSION] Collection Inspection From: tendoaki@gmail.com (Michael Morris) --001a113bddf4d57e2505639f7f0e Content-Type: text/plain; charset="UTF-8" On Thu, Jan 25, 2018 at 2:10 PM, Rowan Collins wrote: > On 25/01/2018 14:52, Derick Rethans wrote: > >> 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; >> > > So would I be right in thinking this would mean adding basic support for > generics to the engine, but not letting new ones be defined in userland? > So, a bit like how internal or extension classes have the ability to do > more overloading of casts and operators than userland classes? > > If so, I like the concept, but wonder whether the parts of the > implementation it would need are the easy parts of the hard ones. I guess > not being able to inherit from the generic would get rid of a bunch of > complexity, but don't really know where else the challenge lies. > He's getting the syntax from Java. Java collections allow you to specify the type they are constrained to in <> after the class name. Type Script does something similar. The problem is that Java already has the policing mechanics present in the runtime to police insertions into the collection and guarantee they are of the correct type. PHP has no such mechanism in place and in previous discussion threads the primary maintainers have underscored that adding such is highly difficult. It is also completely tangential to and a distraction from what I propose and would like to focus on here. Regardless of whether PHP ever gets a core class or construct for type uniform collections, the ability to verify that variables are a "collection of something" will remain. That is the issue I want to discuss and address here - verifying that existing variables are a given collection type, not debating pie-in-the-sky, may never be implementable classes that self insure their own integrity. So, given `$a collectionof string` the operator returns whether or not $a is, at that time, a collection of strings (be it an array or other iterable). It doesn't insure $a will stay that way - it's just a check of the variables status at a given moment, which is the best that can be hoped for in PHP. --001a113bddf4d57e2505639f7f0e--