Req #81522 [Opn->Sus]: Switch...case as an expression
| From: | requinix@php.net | Date: | Tue, 12 Oct 2021 19:03:05 +0000 |
| Subject: | Req #81522 [Opn->Sus]: Switch...case as an expression | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-237172@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81522&edit=1
ID: 81522
Updated by: requinix@php.net
Reported by: kalonya at outlook dot com
-Summary: Switch...case feature request
+Summary: Switch...case as an expression
-Status: Open
+Status: Suspended
Type: Feature/Change Request
-Package: *Programming Data Structures
+Package: *General Issues
Operating System: Irrelevant
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
You're asking for switch to be possible as an expression rather than only as a statement. This
is not a simple change to the language and so would require using the RFC process.
https://wiki.php.net/rfc/howto
But you can already do something simple like this using arrays.
https://3v4l.org/K3DAL
Previous Comments:
------------------------------------------------------------------------
[2021-10-12 18:55:21] kalonya at outlook dot com
Description:
------------
I don't know if this is the right place but I'd like to be able to use switch...case like
Java. Without using "break" and assigning the returned value to a variable directly.
Test script:
---------------
<?php
$day = 2;
$today = switch($day) {
case 1 -> "Monday";
case 2 -> "Tuesday";
case 3 -> "Wednesday";
case 4 -> "Thursday";
case 5 -> "Friday";
case 6 -> "Saturday";
case 7 -> "Sunday";
default -> "Out of day range!";
}
echo "Today is: " . $today . ".";
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81522&edit=1