Why doesn't PHP allow private const?

I have a class that uses the use of constants in an internal implementation, but I would like to limit the visibility of these constants. Why doesn't PHP allow private constants? Is there any other way to achieve this or is it PHP trying to refuse some wrong design that I don't know about?

+69
private oop php encapsulation const
Jul 21 '11 at 1:30
source share
2 answers

Use private static properties.

In this case, you will have the same variable in all objects, and if you want to expand its scope to a nested one, you can provide a retrieval method to get its value and restrict the settings of variables.

+58
Jul 21 '11 at 1:40
source share

As with PHP 7.1, there are real private constants.

 private const PRIVATE_CONST = 0; 

See RFC for details.

+61
Mar 06 '16 at 14:34
source share



All Articles