A PHP internals mailing list discussion around a proposed RFC to add literal scalar types to PHP, allowing function signatures to express exact allowed values like `0|1|2` or `'success'|'error'`. The RFC author argues literal types fill gaps that enums cannot: describing existing scalar APIs without breaking callers, ad-hoc open value sets that can grow without BC breaks, and direct scalar interop (JSON round-trips, array keys, === comparisons with raw values). Skeptics counter that enums already handle most cases through backed enum values and a gradual migration path, and that literal types in signatures produce poor error messages. The discussion converges on a complementary view: enums for named, reusable, behaviour-carrying sets; literal types for raw scalar data like decoded JSON payloads and discriminated unions on the wire.

47m read timeFrom externals.io
Post cover image
136 Impressions