The Switch Statement

Could someone shed some light on why this does not work:

switch $this->_contentType {
            case strpos(this->_contentType,"application/json") !== false:
               // Do something
            break;

            case strpos(this->_contentType, "x-www-form-urlencoded") !== false:
                // Do something
            break;

            default:

            break;
        }

While this IF statement does work:

if strpos(this->_contentType, "x-www-form-urlencoded") !== false{
            let this->_params["contentType"] = "Form URLEncoded";
        }

I am assuming that there are restrictions on the complexity of the 'case' test condition.

The manual states a switch working such that it "evalutes an expression against a series of predefined literal values". You're trying to put your expressions in where the literal values should be (in the case blocks), so this just won't work. As an example, you'd need to think of the switch more like:

switch strpos(this->_contentType, "application/json") !== false {
    case true:
        echo "Have application/json string\n";
        break;
    default:
        echo "Not application/json string\n";
        break;
}

But unless you want to do multiple switches to test for the different strings you want, or nested switch blocks, you're probably better off doing your checks some other way.