0

hello in my PHP file i got error on host for this line that defines const array:

const telegram_methods=['sendMessage'=>'sendMessage','answerCallbackQuery'=>'answerCallbackQuery','forwardMessage'=>'forwardMessage'];

after some changes in host configurations. the error is:

Parse error: syntax error, unexpected '[' in /........./st_datas.php on line 8 

what is the problem of this line or host configurations? and this post: PHP Parse/Syntax Errors; and How to solve them? is so general and not duplicate of my question.

Solivan
  • 695
  • 1
  • 8
  • 16

3 Answers3

1

Maybe for your php version. If your php version >= 5.4, you can use brackets to define array.

So try it:

const telegram_methods = array('sendMessage'=>'sendMessage','answerCallbackQuery'=>'answerCallbackQuery','forwardMessage'=>'forwardMessage');
Mohammad Hamedani
  • 3,304
  • 3
  • 10
  • 22
1
const telegram_methods=array('sendMessage'=>'sendMessage','answerCallbackQuery'=>'answerCallbackQuery','forwardMessage'=>'forwardMessage');
1

In regards to your follow up question (arrays are not allowed in class constants) it means simply as it says.

This has been updated in PHP 7 but before then if you need to set a class variable as an array simply drop the constant.

Check out the comments here for a more detailed response.

http://php.net/manual/en/language.oop5.constants.php

Scootaloot
  • 41
  • 4