Specify More "case" in switch parameters

Posted by Sophie Mackeral on Stack Overflow See other posts from Stack Overflow or by Sophie Mackeral
Published on 2013-11-03T21:51:00Z Indexed on 2013/11/03 21:53 UTC
Read the original article Hit count: 230

Filed under:

I have the following code:

$ErrorType = null;
                                switch ($ErrNo){
                                    case 256,1:
                                        $ErrorType = "Error";
                                        break;
                                    case 512,2:
                                        $ErrorType = "Warning";
                                        break;  
                                    case 1024,8:
                                        $ErrorType = "Notice";
                                        break;  
                                    case 2048:
                                        $ErrorType = "Strict Warning"; 
                                        break;  
                                    case 8192:
                                        $ErrorType = "Depreciated";
                                        break;                          
                                }

But the problem is, I'm going from the pre-defined constants for an error handling software solution.. I cannot specify more than one "case" for the dedicated error categories, example:

switch ($ErrNo){
 case 1:
     $ErrorType = "Error";
     break;
 case 256:
     $ErrorType = "Error";
}

That's a repeat of code.. Whereas with a solution like my first example, it would be beneficial as two integers fall under the same category.. Instead, i'm returned with the following:

Parse error: syntax error, unexpected ',' in Action_Error.php on line 37

© Stack Overflow or respective owner

Related posts about php