Paul Burilichev Paul Burilichev - 1 year ago 74
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);
case "call_ask" :
$subject = "Просьба позвонить";
case "calculator" :
$subject = "Калькулятор";
$user_email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
default :
$output = json_encode(['type' => 'error', 'text' => 'Запрос из неверного типа формы.']);

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

Answer Source

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' => 'Запрос из неверного типа формы.'));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download