A PHP internals mailing list discussion about a proposed RFC to add literal scalar types to PHP, allowing function signatures to express exact values like `0|1|2` or `'success'|'error'` as types. The RFC author argues literal types complement enums by covering cases enums can't handle well: describing existing scalar APIs without breaking callers, ad-hoc open value sets, and scalar interop (e.g., JSON round-tripping). Respondents debate whether enums already cover these use cases, with one commenter arguing literal types would produce poor error messages and that enums can be migrated to incrementally. The RFC author clarifies the primary use case is typing raw scalar data like decoded JSON payloads, where enum-to-scalar conversion overhead is undesirable. A range syntax extension (e.g., `int -1..1`) is also suggested as a future consideration.

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