Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101683 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8852 invoked from network); 26 Jan 2018 01:06:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jan 2018 01:06:38 -0000 Authentication-Results: pb1.pair.com smtp.mail=tendoaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tendoaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.174 as permitted sender) X-PHP-List-Original-Sender: tendoaki@gmail.com X-Host-Fingerprint: 209.85.213.174 mail-yb0-f174.google.com Received: from [209.85.213.174] ([209.85.213.174:43791] helo=mail-yb0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A6/80-04233-D1F7A6A5 for ; Thu, 25 Jan 2018 20:06:38 -0500 Received: by mail-yb0-f174.google.com with SMTP id h9so3781767ybg.10 for ; Thu, 25 Jan 2018 17:06:37 -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=5EdcqWSF3+WP6n7awPz4LGYexqmgpETMbsf8neKqjwM=; b=lNzhqpKEQSlHVXirD096ckvoFNK04JdtA7XGX8kSZT2VLK05vflaA3gP2W3Wp8My/l S4+BX++n60RN0R4A6FNhGPwKXTSEwF7R06QDRO51EgMBNAkRFCDfYPeFz2CtQSP2xA8h TncIhcv+80Z+MCAciQdBTQpz1pP5K+0XMM+GgT1axKqjCjl3ZxCDi62sxN/nHrg5Ce73 oAcr215H8mH+oPFE0YIavoDmICo/ycjSD362iMX53Lkxb0M3J3uOHPnWKQrpxneBO25I p6PyZmSRiXcKA6Yrr2klzgOUNZMMYkGDvbvTSXdZlgx6R5I+zDjKQy7h/PDOEIw5Rmuu eVfA== 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=5EdcqWSF3+WP6n7awPz4LGYexqmgpETMbsf8neKqjwM=; b=P48P0E0F4fSQs112NAhFwJpEQEmZbdiTHZ9hPpDYldb51U4ftG5EJn2DqVsRudt3DM /2rCXzvlC7KofoBivIkT6LHjOXpvTqHgAPCq4a3YmmRXmPhW6A+/1JxBMGXXMjeuAJkL 3ydKfJZjXUPOdzPCHWTHHrqNE4iajfbEKPYC9VhuI0UpjUOG3yBWc5bwz5kZ6D820frg wdqWuahukz9f5YUFqr/fuO8pZKmkb7H/M4gffUX2u0/516CmIqE/b5yJuD1CUteIn2RA iqr8VQX6+/FTPby4mbfbf63BP0shrsLowU5RAP6VIkzX5mL15KC3i9APL6YxnShQyu6V /Ztg== X-Gm-Message-State: AKwxytemjvtnxEscHGi5RgspDIlNz2y/NTSVxXTNbZjvzQj+eykHlXIq A95cG/mG0Yd40jRpUPJA6+F1CrZi9yFsRg9puVzG1Q== X-Google-Smtp-Source: AH8x225RawwFPjyCk8zoKS6AJ+bPeEuBfRnWrewLOJD3quRMQ6XBYLfWStHY3OurbXUtDPhHr9N9liEd1vK+FZnuUsI= X-Received: by 10.37.229.67 with SMTP id c64mr9773953ybh.131.1516928794563; Thu, 25 Jan 2018 17:06:34 -0800 (PST) MIME-Version: 1.0 Received: by 10.37.189.16 with HTTP; Thu, 25 Jan 2018 17:06:34 -0800 (PST) In-Reply-To: References: <9b12b0e2-185e-86fb-0e0b-c4f24bfbd661@gmail.com> Date: Thu, 25 Jan 2018 19:06:34 -0600 Message-ID: To: Niklas Keller Cc: PHP internals Content-Type: multipart/alternative; boundary="94eb2c087652f31b680563a38173" Subject: Re: [PHP-DEV][RFC][DISCUSSION] Collection Inspection From: tendoaki@gmail.com (Michael Morris) --94eb2c087652f31b680563a38173 Content-Type: text/plain; charset="UTF-8" On Thu, Jan 25, 2018 at 3:04 PM, Niklas Keller wrote: > >> >> $a instanceof array >> > > That might work, but array should only return true if it's an > array, not for anything that implements ArrayAccess. > > Related: On Thu, Jan 25, 2018 at 4:11 PM, Levi Morrison wrote: > > > I see no value to this operator being applied to non-array > traversables. If an array access object can't masquerade as an array it loses some of its value, but Niklas is right - it is important to distinguish such objects from native arrays. One solution would be to promote "iterable" to keyword status. The flexibility to take any iterable will be needed I think. $a instanceof iterable Would return true for anything iterable (which we can already test with is_iterable() ) where all values where strings. On Thu, Jan 25, 2018 at 4:11 PM, Levi Morrison wrote: > > Our iterators cannot always be reliably rewound, such as > when using generators. Checking that the generator returns only > strings would consume all the input and would therefore be useless. True - I hadn't thought of those. But as of PHP 7 generators can type declare their return value. So, given `$a instanceof iterable`, if $a is a reference to a generator, then the engine could check the return type declaration and only give true on a match without attempting to use the generator. We can follow this pattern farther - The return of an ArrayAccess::offsetGet and Iterator::current() can be similarly tested by instanceof rather than actually pulling data from these methods. We are having the return rely on the promise of the code, but in each case TypeError would be raised anyway if it breaks it's promise to instanceof so errors aren't being avoided. > Returns true if $a is an array (or implements array access) and that all >> it's members are strings. >> >> $b instanceof SomeClass >> >> Returns true if SomeClass can be iterated and contains only strings. >> > > This would block generics with that syntax then. > I don't understand this comment. On Thu, Jan 25, 2018 at 5:28 PM, Larry Garfield wrote: > > > Is this to ensure that everything coming OUT of a collection is a given > type, > or that everything put IN a collection is a given type? > Ensure (or try to ensure, since reporting the promises of another method's return type isn't certain) that things coming OUT are a given type. Leave the headache of guarding inputs for another day and RFC. > > Asserting that "at this point in time, everything in this collection is a > given type" is honestly fairly useless unless it's enforced to stay that > way. No more useless than type declarations are if a programmer does this... function foo (string $a) { $a = (int) $a; } Every feature of the language can be rendered useless by the right amount of stupidity. No feature recommendation should be beholden to the "what if a moron does X?" argument. --94eb2c087652f31b680563a38173--