Skip to content

Implement a shorter way of defining empty classes #17267

@nbro

Description

@nbro

Description

You can define empty classes with $a = new stdClass();.

However, I think that, not only this is a misnomer, because this std is supposed to mean standard and this is not really a standard class (or a base super class) but an empty class, but that we should have a shorter way to create these classes, in the same way that we can create arrays now with [ ].

I don't know what the best syntax might be, but what about $a = {};?

We should also be allowed to define classes like $a = {"a" = 3} (or something like this or maybe even be able to mimic JSON, so {"a": 1, "b": {"c": 3}}), i.e. pre-populate the classes (if we already know some properties).

I know that this syntax may be confused with dictionaries, but then JavaScript (for example) also uses something like this.

This syntax would also be somehow consistent with JSONs and one use case of these classes is also to deal with JSONs.

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