Skip to content

Require typed class constants #87

Open
@dpi

Description

@dpi

https://wiki.php.net/rfc/typed_class_constants

Since PHP 8.3, class constants can be typed.

Seems to make sense, considering you can subclass and override constants. Typing a constant enforces it down the line. Particularly useful in tests.

Rule: SlevomatCodingStandard.TypeHints.ClassConstantTypeHint

New rule introduced in the latest version of slevomat/coding-standard

Mostly autofixable. In scenarios where a constant isnt subclasses, phpcbf can add types. However things like bools, the autofixer might add true or false, but not pick up hierarchy and set to bool. It also seems like if a constant is a classname CLASS::class, string isnt added, but thats an easy fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions