A PHP internals mailing list discussion about 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 enums cannot: describing existing scalar APIs without breaking callers, ad-hoc open value sets that can grow without BC breaks, and direct scalar interoperability (JSON round-trips, array keys, === comparisons with raw values). Respondents debate whether enums already cover these cases, with one contributor arguing the strongest use case is typing structured scalar payloads like decoded JSON responses where enum conversion overhead is undesirable. A counter-proposal for a non-exhaustive enum marker is also mentioned as an alternative approach.

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