A PHP internals mailing list discussion around a new RFC proposing literal scalar types for PHP, allowing function signatures to express exact accepted values like `0|1|2` or `'ascii'|'utf-8'` directly in type positions. The RFC author argues this fills gaps that enums cannot: retrofitting existing scalar APIs without breaking callers, ad-hoc open value sets that can grow without BC breaks, and native scalar interop (array keys, JSON, strict equality). Participants debate whether enums already cover these use cases, discuss the strongest motivating case (annotating existing PHP built-ins like `array_filter`'s `$mode`), and explore potential extensions like integer range types (`-1..1`). The RFC explicitly excludes constant references and enum case values from type positions, and intentionally supports mixing literal types with wider types in unions.

14m read timeFrom externals.io
Post cover image
57 Impressions