Skip to main content

PHP 8.3 Typed Class Constants

PHP 8.3 added type declarations for class constants. const VERSION: string = ‘1.0.0’; rejects an integer at compile time. The same applies to enum cases and interface constants.It …

April 16, 2026 PHP chris 1 min read Architecture

Article takeaway

PHP 8.3 added type declarations for class constants. const VERSION: string = '1.0.0'; rejects an integer at compile time. The same applies to enum cases and interface constants.It …

PHP 8.3 added type declarations for class constants. const VERSION: string = '1.0.0'; rejects an integer at compile time. The same applies to enum cases and interface constants.

It closes a long-standing gap — until 8.3 a constant’s type was inferred from its value with no way to lock it down. Static analysers like PHPStan and Psalm already enforced this; now the runtime does too.

It also helps with refactors: if you change a constant’s type, subclasses fail to compile until they match.

Share X / Twitter LinkedIn

Leave a comment

Related Posts