Why doesn't PHP permit private const?

leo picture leo · Jul 21, 2011 · Viewed 20.7k times · Source

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 private constants? Is there another way to achieve this or is PHP trying to discourage some type of design misstep I am ignorant of?

Answer

Jeroen De Dauw picture Jeroen De Dauw · Mar 6, 2016

As of PHP 7.1, there are real private constants.

private const PRIVATE_CONST = 0;

See the Class Constant Visibility RFC for more information.