PHP 8.3 typed class constants: who is actually using them
PHP 8.3 added typed class constants:
Two months in, curious whether anyone is using this in production and what the experience is.
Using them in a couple of new projects. The main benefit is that they show up in static analysis with the correct type, and you catch type mismatches earlier. Not a huge win but a small improvement.
They are nice for interface constants which previously had no type guarantee. Child classes could override with incompatible types. Typed constants in interfaces prevent that.
I still mostly use Enums for typed constants with a fixed set. Typed class constants are more useful for single constants or constants that are not really an enumeration.
Minimal code benefit for the added syntax noise in most cases. Enums cover the common cases better. I am not retroactively adding types to existing constants.
PHPStan was already inferring types from constant values reasonably well. The explicit type is more documentation than it is error prevention in practice.
```php blocks are runnable.