A PHP internals mailing list thread discussing the proposed Primary Constructors RFC for PHP. The RFC proposes a new syntax allowing class properties to be declared directly in the class signature (e.g., `class Money(public readonly int $amount) {}`), saving a few lines over traditional constructor promotion. Key debate centers on whether primary constructors should support a body for initialization/validation logic. The RFC author (Rob Landers) argues bodies are intentionally excluded and belong in a follow-up RFC, citing that 30-70% of real-world constructors could already benefit without bodies. Critics (notably Nick Sdot) argue the feature is too limited without body support, particularly for readonly classes where property hooks don't work, and warn against PHP's pattern of shipping incomplete features that never get properly finished.

1h 14m read timeFrom externals.io
Post cover image
115 Impressions