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 these fill gaps enums cannot: typing 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, backed enums cover scalar interop, and a gradual enum migration path exists for legacy APIs. The discussion also touches on potential range types (e.g., `int -1..1`) as a future extension, and the author clarifies that literal types shine most for typed structured payloads like decoded JSON responses where data is genuinely scalar on the wire.

27m read timeFrom externals.io
Post cover image
74 Impressions