|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #38487 Improving switch statement
Submitted: 2006-08-18 02:07 UTC Modified: 2015-09-07 00:47 UTC
Avg. Score:3.2 ± 1.5
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:3 (75.0%)
From: dtyschenko at soft-ukraine dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.1.5 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2006-08-18 02:07 UTC] dtyschenko at soft-ukraine dot com
I think use switch in case like this will be very useful  

Reproduce code:
	switch ($a instanceof) {
		case Foo : echo "Foo"; break;
		case Bar : echo "Bar"; break;
		default : echo "Unknown" : break;


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-06 18:27 UTC] 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;
 [2015-09-07 00:47 UTC]
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 [2015-09-07 00:47 UTC]
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.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Oct 24 15:03:33 2021 UTC