Skip to content

Feature Request: multiple class property initialization without constructor #17041

@blacktrs

Description

@blacktrs

Description

With constructor property promotion we're already achieved ability to skip a lot of boilerplate code. With property accessors (aka hooks) we could rid of getters and setters. But often classes need constructors only to set properties. And in such cases, constructors become redundant.

Thus, we would have possibility to skip constructors to initialize multiple properties at once:

readonly class User
{
   public string $name;
   public int $age;
}

$user = new User {
    name: "John",
    age: 42,
};

As a result, classes would be initialized in struct-like way. In looks like useful additional for "data" classes/DTOs etc.

I suppose it was discussed but was unable to find exact rfc or discussion.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions