PHP Class Constants - Public, Private or Protected?

前端 未结 4 945
余生分开走
余生分开走 2020-12-09 14:43

Am I correct in assuming that const properties are automatically public? Is there a way to make them private or protected?

Thanks in advance.

4条回答
  •  不知归路
    2020-12-09 15:14

    Historically, class constants were always publicly accessible as long as the class was loaded and there was no way to change this.

    As of PHP 7.1, they remain public by default but access modifiers may now be applied. Here's the example from the release notes:

提交回复
热议问题