-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
  • 57,247
  • 24
  • 95
  • 149
Alexey Tseitlin
  • 871
  • 1
  • 11
  • 28

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
  • 293
  • 1
  • 3
  • 9