Why doesn't PHP permit private const?

前端 未结 2 962
心在旅途
心在旅途 2020-12-05 12:51

I have a class that benefits from the use of constants in its internal implementation, but I would like to limit visibility of these constants. Why doesn\'t PHP permit priva

相关标签:
2条回答
  • 2020-12-05 13:16

    Use private static properties.

    In that case you will have the same variable throughout all objects and if you want to extend its scope to nested, you can expose a getter method to get its value and restrict variables settings.

    0 讨论(0)
  • 2020-12-05 13:18

    As of PHP 7.1, there are real private constants.

    private const PRIVATE_CONST = 0;
    

    See the Class Constant Visibility RFC for more information.

    0 讨论(0)
提交回复
热议问题