Req #38487 [Opn->Wfx]: Improving switch statement
Edit report at https://bugs.php.net/bug.php?id=38487&edit=1
ID: 38487
Updated by: requinix@php.net
Reported by: dtyschenko at soft-ukraine dot com
Summary: Improving switch statement
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
PHP Version: 5.1.5
Block user comment: N
Private report: N
New Comment:
I'm going to mark this wontfix, on the original proposal, for three reasons:
1. It's a very specific use case
2. I imagine it would require a specific syntax "exception" in the PHP parser to support a
switch+interfaceof+case class names
3. You can already do this:
switch (true) {
case $a instanceof Foo: echo "Foo"; break;
case $a instanceof Bar: echo "Bar"; break;
default: echo "Unknown"; break;
}
Regarding using "case" in the condition, I think that's more feasible. @david.proweb,
if you'd like to push for this feature then I suggest bringing it up on the internals mailing
list for discussion.
Previous Comments:
------------------------------------------------------------------------
[2015-09-06 18:27:59] david dot proweb at gmail dot com
It'll be a problem because of PHP structure. But maybe use/create a keyword to receive the case
value.
switch ($a instanceof case) {
case Foo : echo "Foo"; break;
case Bar : echo "Bar"; break;
default : echo "Unknown" : break;
}
------------------------------------------------------------------------
[2006-08-18 02:07:16] dtyschenko at soft-ukraine dot com
Description:
------------
I think use switch in case like this will be very useful
Reproduce code:
---------------
<?php
switch ($a instanceof) {
case Foo : echo "Foo"; break;
case Bar : echo "Bar"; break;
default : echo "Unknown" : break;
}
?>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=38487&edit=1
Thread (3 messages)