From:             php at dafydd dot com
Operating system: Mac/Doesn't matter
PHP version:      5.2.5
PHP Bug Type:     Feature/Change Request
Bug description:  Allow switch() to track multiple variables.

Description:
------------
In writing with PHP, I have frequently come across situations where I
would have to nest switch() functions. So, I thought of an alternative.

Reproduce code:
---------------
Current code:

Suppose I have one variable limited to four specific values, and a second
variable that identifies whether or not the first variable can be changed.
Right now, I have to do this:

switch ($value) {
  case 'a':
    switch ($access) {
      case 'read-only':
      case 'read-write':
    }
  case 'b':
    switch ($access) {
      case 'read-only':
      case 'read-write':
    }
  case 'c':
    switch ($access) {
      case 'read-only':
      case 'read-write':
    }
  case 'd':
    switch ($access) {
      case 'read-only':
      case 'read-write':
    }
}

Expected result:
----------------
Instead of doing that, how about changing switch to track multiple
variables. Perhaps like this:

switch ($value, $access) {
  case ('a', 'read-only'):
  case ('a', 'read-write'):
  case ('a', default):
  case ('b', 'read-only'):
  case ('b', 'read-write'):
  case ('b', default):
  case ('c', 'read-only'):
  case ('c', 'read-write'):
  case ('c', default):
  case ('d', 'read-only'):
  case ('d', 'read-write'):
  case ('d', default):
  case (default, default):
}

This would reduce repetition in coding!


Actual result:
--------------
I fully anticipate that this would be an "incorporate into PHP 7" class of
new feature. 

-- 
Edit bug report at http://bugs.php.net/?id=44298&edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=44298&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=44298&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=44298&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=44298&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=44298&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=44298&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=44298&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=44298&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=44298&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=44298&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=44298&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=44298&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=44298&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=44298&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=44298&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=44298&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=44298&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=44298&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=44298&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=44298&r=mysqlcfg

Reply via email to