Re: [RFC] Match expression

From: Date: Sun, 10 Sep 2017 20:35:55 +0000
Subject: Re: [RFC] Match expression
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-100513@lists.php.net to get a copy of this message
On 10/09/2017 20:35, lists@rhsoft.net wrote:
the whole switch discussion is broken by design with "<?php declare(strict_types=1);" the intention is pretty clear
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.
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).
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. 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; } Although an obvious question would be why switch gets such a version, and what other language constructs should follow suit. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#100513) next »