Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101678 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 95937 invoked from network); 25 Jan 2018 21:54:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Jan 2018 21:54:31 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.66 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.66 mail-wm0-f66.google.com Received: from [74.125.82.66] ([74.125.82.66:43318] helo=mail-wm0-f66.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4E/F5-61119-6125A6A5 for ; Thu, 25 Jan 2018 16:54:30 -0500 Received: by mail-wm0-f66.google.com with SMTP id g1so17395811wmg.2 for ; Thu, 25 Jan 2018 13:54:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=BeL/4zZrYOx1dQhCGb++zSaXm4zIGpE+LU4/EqZyj+o=; b=ND3UXrDvi98xiZSMMxpTmRALD7W9IT7da5Isy2o9zCAgQq5g40lxk9SjfruvPrFIoH SF1YdpWXWgPSiIYl1NKLg6Ld6LtjPPfQLtGXNkbwqdFKCmTPn+mpfUrYz7nGywUdAF/l 2vsEfScW/nBFEniQeLBhsnXyeWCb/DcI/EjmrdcIvtY/9LGo5CcTBgkD3nM0x1umSz7d iABVLlQ2XJRILir5zcVEkdlnPoVxhL39kAS78/do9DZLHqY7oZT7PklfA2iE1OszBCJr ROXxvk54/17SWRNPhy/LpSyNzFjftpXxW73JjC+kW2uRYRFIFoc9fWebgHlBnYG9GJqw dXEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=BeL/4zZrYOx1dQhCGb++zSaXm4zIGpE+LU4/EqZyj+o=; b=SlCdcsb3LFjoRNSz1e8gV0k4hG2uYGvP8DOVb6ly9a6y7+/517tKwTHNT3O1UEpWyI sCgzTl5pb2gBkQgMlNlGfUbgNdtrvkzs781coDqHJhwaNCNSHE1Cdt8E3FAWrwcr5fax Cyux2ADSOpjr1MofVWt+jpdsjueubt/a6U2IgzxBj9TeEy6lmlxRUpqBwnjXRQy4WtBB G3FkddN/sFPEKbUT/EWH5sAfa5UsEA9O3hjsIWP1wIiVlDky1znMYWB9zHCJ/n0QIAHm kdl0RK1gAan54QLIHHbtkrAY2PvZ+/ORDZ6D5MB/Z4INLU8dkmTi3pYwuGLZ28O1nyfH +Jlw== X-Gm-Message-State: AKwxyteIS85R9tBPxhqZmVYz7RkciF+QesWW9SnmpdKOURzftd9e+LeU FT4Dr/aWAKAOlGVXNL6rm72Ebw== X-Google-Smtp-Source: AH8x227lGnAca0W1PxP8otILMVu98bydf6iNMiqDuha9kdM49NewoXiTQQsL49UsrHabLas7Ws1cbg== X-Received: by 10.80.246.133 with SMTP id d5mr30500885edn.93.1516917267590; Thu, 25 Jan 2018 13:54:27 -0800 (PST) Received: from [192.168.1.253] (host86-173-114-42.range86-173.btcentralplus.com. [86.173.114.42]) by smtp.googlemail.com with ESMTPSA id e12sm1688265edm.42.2018.01.25.13.54.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jan 2018 13:54:26 -0800 (PST) To: internals@lists.php.net References: <9b12b0e2-185e-86fb-0e0b-c4f24bfbd661@gmail.com> Message-ID: <02e64d55-8c44-1e7b-45a8-a58ba6c00164@gmail.com> Date: Thu, 25 Jan 2018 21:54:26 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB Subject: Re: [PHP-DEV][RFC][DISCUSSION] Collection Inspection From: rowan.collins@gmail.com (Rowan Collins) On 25/01/2018 20:19, Michael Morris wrote: > He's getting the syntax from Java. Actually, from C++, and possibly from somewhere before that; at this point, it's pretty widely adopted. > 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. That's only partially true. As Bishop Bettini pointed out, you can *almost* get there with features already in the language, because you can implement the magic ArrayAccess interface and intercept all assignments using the $foo[]=$val and $foo[$bar]=$val syntaxes. The main problem, as usual, is references: you can't intercept "$ref =& $foo[$bar]; $ref=42;" - if you try, you get a somewhat cryptic notice that "Indirect modification of overloaded element of foo has no effect". Apart from that, this is a *lot* simpler as a problem than general type tracking, because we only care about those two specific operations, not everywhere that performs an assignment of any sort. In that sense, a full implementation of generics is actually simpler: the only actual type checks would be on parameters and return types, where they're already supported, e.g. class Stack { public function push(T $item) { ... } public function pop(): T { ... } } Like I say, it might be perfectly reasonable to have both a collectionof operator and generics in the language, but I don't think it's unreasonable to think about where they overlap. Regards, -- Rowan Collins [IMSoP]