Class Constants With Different TypesΒΆ

With PHP, it is possible to have a class constant with different values, between a parent class, and its child class.

Quizz of the day : can you make a class constant with different types ? Optionally different values.

Works on PHP 8.3. Application unknown.

The trick is to use union types, which allows adding new valid types without ascendant compatibility.

../_images/class_constant_different_types.png