Larry Garfield and Ilija Tovilo have presented a long-awaited PHP RFC for pattern matching, a feature in development since 2020 intended as a stepping stone toward full algebraic data type (ADT) support. The RFC introduces a new 'is' operator enabling structural matching against arrays, objects, and enums, with features like variable pinning and numeric comparison included after a full implementation rewrite. Community discussion on the internals mailing list raises concerns about syntax inconsistencies — particularly the colon prefix for object property binding vs. bare variables in array patterns — and inconsistent handling of uninitialized/undefined object properties compared to arrays. Bob Weinand advocates for an earlier brace-based syntax ({}) for named object matching and parentheses for positional matching, arguing it is more consistent and intuitive. Larry Garfield defends the current colon-prefix approach, citing parsing ambiguities with the brace syntax and noting Dart uses a similar approach. A vote is not expected before late January.

1h 2m read timeFrom externals.io
Post cover image
99 Impressions