Rob Landers has proposed a 'primary constructors' feature for PHP on the internals mailing list, seeking feedback before a formal RFC. The syntax would allow class properties and parent constructor calls to be declared inline in the class signature, e.g. `class Point(public int $x, int $id = 0) extends Base($id);`. This is syntactic sugar for the verbose `__construct` boilerplate. Classes using primary constructors cannot define a separate `__construct` method; validation logic must instead use property hooks. The proposal is inspired by similar features in C# and Kotlin.
136 Impressions