Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) in Laravel project Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) in Laravel project laravel laravel

Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) in Laravel project


The ability to specify the visibility of class constants was only added in PHP 7.1, from the manual page

Note:

As of PHP 7.1.0 visibility modifiers are allowed for class constants.

So on the PHP 7.0 server, the

public const TRANSACTION_READ_UNCOMMITTED ...

lines should not have the public on them. It also says that

The default visibility of class constants is public.

So public is not needed anyway.


It seems like you want to define a constant variable.

My instruction was :

const CONSTANT = 'jkl';

The error I got :

syntax error, unexpected 'const' (T_CONST) in ...

I changed that instruction to :

define('CONSTANT', 'jkl');echo CONSTANT;

output :

jkl

Syntax of the method 'define' :

define('variable_name', 'value_of_the_variable', [case-insensitive_constant_name = true/false]);

For eg.

define('CONSTANT3', 'ghi', true);echo CONSTANT3;define('constant3', 'ghi'); //Defining 'constant3' again will give an error.

But

define('CONSTANT3', 'ghi');echo CONSTANT3;define('constant3', 'ghi'); //This won't give an error.echo constant3;

Always remember that regular variables should be addressed by using '$' before their name but constant variables should be addressed directly as shown by me in the code above.