Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100514 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60251 invoked from network); 10 Sep 2017 23:36:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Sep 2017 23:36:29 -0000 Authentication-Results: pb1.pair.com header.from=lists@rhsoft.net; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=lists@rhsoft.net; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain rhsoft.net designates 91.118.73.15 as permitted sender) X-PHP-List-Original-Sender: lists@rhsoft.net X-Host-Fingerprint: 91.118.73.15 mail.thelounge.net Received: from [91.118.73.15] ([91.118.73.15:50111] helo=mail.thelounge.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3B/C3-10715-B7CC5B95 for ; Sun, 10 Sep 2017 19:36:28 -0400 Received: from srv-rhsoft.rhsoft.net (Authenticated sender: h.reindl@thelounge.net) by mail.thelounge.net (THELOUNGE MTA) with ESMTPSA id 3xr6rl3STkzXMZ; Mon, 11 Sep 2017 01:36:23 +0200 (CEST) To: internals@lists.php.net References: <044d6dc6-63b4-5242-b910-f5a4fdf48eab@rhsoft.net> <66a056cc-87f6-3f5e-0417-6b8ab51cdbae@rhsoft.net> Message-ID: <94abb2fb-5d18-534e-4da4-4dde187ac494@rhsoft.net> Date: Mon, 11 Sep 2017 01:36:23 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-CH Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] Match expression From: lists@rhsoft.net ("lists@rhsoft.net") Am 10.09.2017 um 22:35 schrieb Rowan Collins: > On 10/09/2017 20:35, lists@rhsoft.net wrote: >> with " > strict_types does not currently have any effect on comparisons anywhere, > and nor is it likely ever to do so. It is a very specific option, not a > broad set of behaviours like "use strict" in JS or Perl. in case of a normal comparison you have !== and === to make it explicit >> raise an error if cases are mixed (case 'a' and case 1 under  the same >> switch) > > It's interesting that the behaviour you think is obvious is completely > different to what I think of: if the author of the code has put both > case 42 and case '42' in the switch statement, the "strict" > interpretation in my mind would be that both branches are reachable, as > though tested with an "===" operator (whereas currently the second would > never be selected, because no value =='42' that doesn't also ==42). yes, for non-strict code that's fine >> and also raise an error in a case like below when $a is  anything else >> then int > > I guess this explains the different direction you're coming from: what > you want could perhaps be termed a "strongly typed switch statement", > where both input and case values are checked as soon as possible for > being of some specified type. yes, that's what i expect from declare(strict_types=1); wherever it is possible for several reasons * as developer i like fail early and raise a clear exception * in the best case even at compile time and not 3 days later at runtime * it makes code often more secure over time when it points out missing input validation and from where a bad value comes instead burry a error where it triggers the exception * it enables optimizations like 7.1 got a lot * it even may help a future JIT to optimize due change every code i wrote to strict-types and enhance every function to type-hints and return types i found a ton of hidden probably bugs and especially fuzzying points out code weakness > The logical syntax for that would probably be an explicit type in the > switch statement somewhere, like this: > > switch(int $a) > { >  case 1: ..; break; >  case 2: ..; break; > } i like that! > Although an obvious question would be why switch gets such a version, > and what other language constructs should follow suit. well, you have to start somewhere and the start was done with 7.0 for function params and return types, switch is an obvious place that could be enhanced and the syntax above is 100% consistent to function params it's not only consistent in the syntax, it's also consistent in behavior meaning in no-strict-mode make a implicit type cast and it's not a new syntax element currently i have no other language constrcuts in mind but i think starting here could lead in people point out other places where it makes sense and since it's completly opt-in it don't break any existing code ok, i have one in mind foreach($arr as int $x) raise a runtime error when you expect a array with only numbers and the comes '42' and in strict-mode do a consistent implicit cast in non-strict where you can be sure in both cases that you deal with a int within the loop