A PHP internals mailing list discussion around a proposed RFC to add literal scalar types to PHP, allowing function signatures to express exact accepted 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, handling open value sets that grow without BC breaks, and enabling direct scalar interop (JSON round-trips, array keys, === comparisons with raw values). Critics counter that enums already cover most use cases, backed enums handle scalar interop, and a non-exhaustive enum marker RFC could address open sets. The strongest acknowledged use case is typing structured scalar payloads like decoded JSON responses, where enums require constant conversion via `->value` and `::from()`.

58m read timeFrom externals.io
Post cover image
97 Impressions