Class Constants With Different Types

no-email (Damien Seguy), Damien Seguy
Sat, 27 Jan 2024 00:00:00 +0000

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.