Why doesn't PHP permit private const?

前端 未结 2 969
心在旅途
心在旅途 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.

提交回复
热议问题