-2

In PHP docs there is an example that uses public const http://php.net/manual/en/language.oop5.visibility.php#example-196

class MyClass
{
    public const MY_PUBLIC = 'public';
}

But it gives me this error: "Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) in /Applications/MAMP/htdocs/php-testing/const.php on line 5"

This example works without "public". Like this

class MyClass
{
    const MY_PUBLIC = 'public';
}

What am I doing wrong?

tereško
  • 58,060
  • 25
  • 98
  • 150
Alexey Tseitlin
  • 1,031
  • 4
  • 14
  • 33

1 Answers1

2

Modifiers for constants have been added only in PHP 7.1, be sure to use the right version.

Class Const Visibility

dariush624
  • 343
  • 1
  • 4
  • 9