A PHP internals mailing list discussion around 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 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 author concedes enums are better for named, reusable, behaviour-carrying sets, but maintains literal types are uniquely suited for typed scalar data on the wire, especially in future array shape typing scenarios.

53m read timeFrom externals.io
Post cover image
117 Impressions