Strict switch
| From: | David Rodrigues | Date: | Thu, 26 Nov 2020 16:39:28 +0000 |
| Subject: | Strict switch | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-112299@lists.php.net to get a copy of this message | ||
Hello!
With PHP 8 we have match(), that is a switch strict expression-like. But
strict is not strict, and it could cause confusion because switch() and
match() are pretty similar.
I believe that this has already been discussed, but it would be interesting
to re-evaluate the possibility of a strict() with support for strict.
In order not to generate BC, my suggestion is to attach a specific keyword
for this purpose, or a similar alternative.
(0) switch(8.0) { case '8.0'; return 'no'; case 8.0: return 'yes'; }
// no?
(1) strict switch(8.0) { case '8.0'; return 'no'; case 8.0: return
'yes'; }
// yes
(2) switch strict(8.0) { ... } // yes
(3a) switch(8.0, true) { ... } // yes
(3b) switch(8.0, strict: true) { ... } // yes (named argument)
Or then in the "case":
(4) switch(8.0) { strict case 8.0: ... } // yes
(5) switch(8.0) { case strict 8.0: ... } // yes
Or allowing operators (this would be the most flexible way, as it would
allow for a number of other features):
(6) switch(8.0) { case === 8.0: ... } // yes
Atenciosamente,
David Rodrigues