PHP error for const array [duplicate] - php

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
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.

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');

const telegram_methods=array('sendMessage'=>'sendMessage','answerCallbackQuery'=>'answerCallbackQuery','forwardMessage'=>'forwardMessage');

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

Related

PHP $_SESSION variable in CONSTANT [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Can you undefine or change a constant in PHP?
(6 answers)
Closed 5 years ago.
I am trying to define a session variable as constant ...
define("MY_VAR", $_SESSION['variable_name']);
I start the session before accessing this constant
However, when I try to change the value of the variable ...
MY_VAR = "xyz"
... I get following message
"Parse error: syntax error, unexpected '=' in"
I am not sure what's happening here. It would be great if someone could shed some light on this.
Note: Instead, if I use $_SESSION['variable_name'] at all places where I used MY_VAR, the code works fine
The point of constants is they are constant.
Once set you can't change them.

vqcache/vq2-catalog_controller_common_header.php [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I am receiving this error message:
[17-Mar-2017 10:22:14 America/Detroit] PHP Parse error: syntax error, unexpected end of file in /home/smarthea/public_html/ocart/vqmod/vqcache/vq2-catalog_controller_common_header.php on line 50
Here is the end of my code in the vqcache PHP file:
$this->template = 'default/template/common/header.tpl'; }
{ $this->render(); }
?>
Which syntax am I missing?
See you modification-file. You just missed line number. Just look into instructions in modificator and correct it.
This error usually appear when you're using several vQmod mofificators that used same file. In you case they modify /catalog/controller/common/header.php

Concat Constant in php [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
namespace my;
const DHA=__NAMESPACE__."you are accessing constant"; //generate parse error
const DHA=__NAMESPACE__,"you are accessing constant"; //generate parse error
I tried concating using '.' and ',' but both it gives
Parse error: syntax error, unexpected '.', expecting ',' or ';'
EDIT (UPDATE) : This is a bug in PHP 5.5. It has been resolved in 5.6. https://wiki.php.net/rfc/const_scalar_exprs.
Which version of PHP
See https://bugs.php.net/bug.php?id=42355
Considered a new feature in 5.6
I have 5.5.9 right now and get the same results as you do

Are the brackets used to define an array in php not supported? [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I tried to define an simple array in php, and I got an "unexpected '[' error message.
Code:
<?php
$days = ["Mon","Tue","Wed","Thu","Fri"];
echo "Value at index 1 is ". $days[1];
?>
while using the $days = array("Mon","Tue","Wed","Thu","Fri"); works fine
If your version of PHP is < 5.4 you cannot use [] to define an array. Create a page that contains:
<?php phpinfo() ?>
and see what version that says. Alternatively, if you have shell access to the server you're working on, typ this on the command line:
`php -v`

VatNumber Validation using SOAP client [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I'm having a problem in my script class, is giving me the error:
Parse error: syntax error, unexpected '$client' (T_VARIABLE), expecting identifier (T_STRING)
But I can't figure out what is the problem with the "client Variable".
While accessing constant class members you need to use self::, but while
accessing local variable you can use simply by variable name.
So you need to use self::client instead of $client. Because $client is constant class member.
DEMO or See More Info

Categories