Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101026 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64987 invoked from network); 2 Nov 2017 04:32:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Nov 2017 04:32:08 -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.161.170 as permitted sender) X-PHP-List-Original-Sender: tendoaki@gmail.com X-Host-Fingerprint: 209.85.161.170 mail-yw0-f170.google.com Received: from [209.85.161.170] ([209.85.161.170:50507] helo=mail-yw0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 16/3F-07742-3CF9AF95 for ; Wed, 01 Nov 2017 23:32:04 -0500 Received: by mail-yw0-f170.google.com with SMTP id i198so3690909ywe.7 for ; Wed, 01 Nov 2017 21:32:03 -0700 (PDT) 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=TfvY68lewhOWIBTmAu6cbWx0fPv+BPtgT7Xr/G4VFGM=; b=p29wthwgfX/7oUzaNnavIBM/2w5bx9BUtMiqJu5O6n294x+jpxdLyeyhj12gcxCC96 JlnN2HhN6XpJJAf3ryIWqf+chCZ9/C7VgfYMy4i9PuZGYoSjt7vORIDA3NZmZwl6aL6n /2jTs4hwQQUDsH9r0GHKM8QHXKB0Bu561keYsupH5FUw542L44QonyrsIMMYnMuJuAha 4I1nFKhSKDZhk/9Ikr52mBFqJ68+i7YL7hsoTatRP42bhMkgnV4yAght6PxkFJVS+9ib qo7MviEq2kGMNRMNIf/Pd+8NnLPEpM/iHYEuBOrMLRpuQIRgh+kghzY1mK6NGpchUtjB geuQ== 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=TfvY68lewhOWIBTmAu6cbWx0fPv+BPtgT7Xr/G4VFGM=; b=NYn0axBHqW53J53xPTlym2gbJ+CjPcqB73VdkJ+4D66U2Tkhj45JponqDwl7qKaJCs Cu00i+4MhuMO6E1dzaCIkv/SMgXTk3U7kWi9sQ/osr5NTul1dLN62wg4rVzHUKl55YUf ZItobFyCh6Wv+K03a1Tye++tdsVcRj6kdVmLDlJ2ElxruHVB1Wj3DkHs76FJhe/LPAPG IO01mqfnUzXBu5WP0fl0gh9zXzunbwutjuHR2eJBGwjGtFuftETzdOzWbiIMw73HzwAu sGQofvwgRQNxFP+5m8o1xO4rpvI224h8akuVVEZYcF6atcpOkWbyE1PuKyYDDZLm5grM 8Hyw== X-Gm-Message-State: AMCzsaVtCarrU192fl7YgKKG0/MQExxTgOnSnXIe0PuiBqhKVybXfomT VGV4UmgvZzNnve5lnMocecM/motyIJeHwmq0p0w= X-Google-Smtp-Source: ABhQp+SmCpOUlJIZUQpNsYC09yXUlQW9lvu8Vv56bomveKFtSdjg3Drs86dfgrwOoImsiKw0pD98PfqwXszPK/wfc3A= X-Received: by 10.129.112.208 with SMTP id l199mr1510534ywc.480.1509597120342; Wed, 01 Nov 2017 21:32:00 -0700 (PDT) MIME-Version: 1.0 Received: by 10.37.139.141 with HTTP; Wed, 1 Nov 2017 21:31:59 -0700 (PDT) In-Reply-To: <2C3A2443-8680-4FA7-BD25-872472506D03@gmail.com> References: <2C3A2443-8680-4FA7-BD25-872472506D03@gmail.com> Date: Thu, 2 Nov 2017 00:31:59 -0400 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="94eb2c0a8c4a1cb127055cf8780e" Subject: Re: [PHP-DEV] RFC - Array Of for PHP 7 From: tendoaki@gmail.com (Michael Morris) --94eb2c0a8c4a1cb127055cf8780e Content-Type: text/plain; charset="UTF-8" Drupal 8 accomplishes this through assert() and a helper class. function foo ( array $a ) { assert( Inspector::assertAllStrings( $a )); } This could be improved by having an collectionof operator similar to the instanceof operator. function ( array $a ) { assert( $a collectionof string ); } I say "collectionof" because while arrays are the most common traversable objects, they aren't the only ones. The above approach, combined with the existing assert structure, can provide the dev time checking of the code while in under development, and it can be turned off in production. Or it can be used outside of assert to be checked at all times. Since this invokes a new keyword I think that would mean this solution would be PHP 8. Brackets might be used with instance of to notify it to traverse down one level maybe?? function ( array $a ) { assert( $a instanceof [string] ); } This avoids any BC issues, but it looks odd. Not as odd as \ for a namespace operation :P But odd. On Wed, Nov 1, 2017 at 10:40 AM, Rowan Collins wrote: > On 31 October 2017 17:37:17 GMT+00:00, Levi Morrison > wrote: > > - Our current infrastructure requires us to check every element of > >the array for conformance. While undesirable I believe this can be > >optimized away in the future if we care enough, and therefore not a > >show-stopper. > > Do you have a mechanism in mind for "optimising this away"? I think > releasing the feature without any optimisation will just lead to painful > slowdowns when people use it without realising the implications. > > As I said in my previous message, it seems to be a fundamental issue with > PHP's current type declarations that they are a) runtime, and b) asserted > at arbitrary points, not at assignment. So even if you optimise the check > slightly, it's still a separate check every time you enter a new function, > which puts a limit on optimisation. > > The only way I've thought of to improve things is to cache the result of > previous type checks, but this comes with all the normal challenges of > caching. For instance, all assignments into the array would need to > invalidate these cached checks, or check the new value against each. > References would be particularly tricky, as they were with the property > type hint proposal. > > If we selectively invalidated cached checks, we'd be running specific type > checks at every variable assignment, but not letting the user actually > assert on those checks. At which point, should we approach from the other > direction, and let the user declare variable types, rather than assert > value types? > > This is kind of implied if we implement generics, too, since explicitly > constructing an instance of list is asking the runtime to check future > assignments to members of that list. In effect, could declaring "int $foo = > 42;" be considered equivalent to "$foo = new checkedScalar(42);"? > > Regards, > > -- > Rowan Collins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --94eb2c0a8c4a1cb127055cf8780e--