Skip to content

Immutability through a docblock annotation or an attribute #4600

@oprypkhantc

Description

@oprypkhantc

Feature request

Introduce @immutable docblock annotation, similar to what Psalm offers, applicable to classes, traits and properties. The whole implementation should be a few hundreds lines of code: every property that is being assigned checks whether it or it's class/trait is marked as @immutable and, if so, throw an error. Same thing when trying to pass such a property by reference. The only exceptions are the constructor and __unserialize.

Optionally, support for unofficial #[Immutable] annotation of PHPStorm could be introduced as a fallback until there's a single standard for this.

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