Paul Burilichev Paul Burilichev - 5 months ago 7
PHP Question

PHP | Switch statement crashes execution

I have this statement that includes in a php-file. And with it execution crashes. Nothing executes before and after the statement.

switch ($type) {
case "contact_page" :
$subject = "Вопрос со страницы Контакты";
$user_email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
break;
case "call_ask" :
$subject = "Просьба позвонить";
break;
case "calculator" :
$subject = "Калькулятор";
$user_email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
break;
default :
$output = json_encode(['type' => 'error', 'text' => 'Запрос из неверного типа формы.']);
die($output);
}


When I replace this with
if...else
statement all executes good.
Can't find a mistake.

Answer

The php version does not support the new array notation (5.4+ from what I know).

Use in the default case:

 $output = json_encode(array('type' => 'error', 'text' => 'Запрос из неверного типа формы.'));