1

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.

Paul Burilichev
  • 406
  • 3
  • 10

2 Answers2

2

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' => 'Запрос из неверного типа формы.'));
ka_lin
  • 9,329
  • 6
  • 35
  • 56
  • 2
    Yes, it is the problem. Thank you for attention. Really I forget this. – Paul Burilichev Jun 27 '16 at 16:29
  • That's funny that people still in old versions of PHP. For example I use always latest release of PHP (now v. 7) and I don't care if there will be exceptions, I'll fix it. – num8er Jun 27 '16 at 16:30
0

Upgrade PHP to >5.4

or update code from:

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

to

json_encode(array('type' => 'error', 'text' => 'Запрос из неверного типа формы.'));
num8er
  • 18,604
  • 3
  • 43
  • 57