---
title: "lint/classes"
pagination: false
---

{/* Generated by scripts/gen-rule-docs.py. Edit mapping.toml, not this file. */}

Class, interface, trait and enum declarations and their members. Also in [format](/docs/rules/format/classes) (8) and [analyse](/docs/rules/analyse/classes) (64).

**[add-stringable](/docs/rules/lint/classes/add-stringable)**

A class that implements the `__toString()` method must explicitly implement the `Stringable` interface.

In the `modernize` set. Safe fix.

**[no-explicit-constructor-call](/docs/rules/lint/classes/no-explicit-constructor-call)**

Disallows calling `__construct()` on an existing object outside a constructor.

In the `code-quality` set. Report only. Intent: suspicious. Upstream gates: `strictRules.illegalConstructorMethodCall`.

**[no-null-property-default](/docs/rules/lint/classes/no-null-property-default)**

Properties MUST not be explicitly initialised with `null` except when they have a type declaration (PHP 7.4).

In the `dead-code` set. Safe fix.

**[no-protected-constant-in-final](/docs/rules/lint/classes/no-protected-constant-in-final)**

Change protected constant to private if possible

In the `privatization` set. Safe fix.

**[no-protected-in-final](/docs/rules/lint/classes/no-protected-in-final)**

Converts `protected` variables and methods to `private` where possible.

In the `privatization` set. Safe fix.

**[no-protected-method-in-final](/docs/rules/lint/classes/no-protected-method-in-final)**

Change protected class method to private if possible

In the `privatization` set. Safe fix.

**[no-protected-property-in-final](/docs/rules/lint/classes/no-protected-property-in-final)**

Change property to private if possible

In the `privatization` set. Safe fix.

**[no-redundant-readonly](/docs/rules/lint/classes/no-redundant-readonly)**

Removes redundant readonly from properties in readonly classes.

In the `dead-code` set. Safe fix.

**[no-static-constructor-call](/docs/rules/lint/classes/no-static-constructor-call)**

Disallows calling a constructor statically (`Foo::__construct()`) outside a child class's constructor.

In the `code-quality` set. Report only. Intent: suspicious. Upstream gates: `strictRules.illegalConstructorMethodCall`.

**[no-underscore-class](/docs/rules/lint/classes/no-underscore-class)**

Detects class, interface, trait, or enum declarations named `_`.

In the `modernize` set. Report only.

**[no-unset-on-property](/docs/rules/lint/classes/no-unset-on-property)**

Properties should be set to `null` instead of using `unset`.

In the `code-quality` set. Unsafe fix: it can change behaviour. Intent: suspicious.

**[prefer-new-self](/docs/rules/lint/classes/prefer-new-self)**

Change `new static()` to `new self()` in a final class

In the `code-quality` set. Safe fix.

**[prefer-self-in-final](/docs/rules/lint/classes/prefer-self-in-final)**

Inside an enum or `final`/anonymous class, `self` should be preferred over `static`.

In the `modernize` and `code-quality` sets. Safe fix.

**[require-class-matches-file](/docs/rules/lint/classes/require-class-matches-file)**

Classes must be in a path that matches their namespace, be at least one namespace deep and the class name should match the file name.

In the `code-quality` set. Unsafe fix: it can change behaviour. Intent: correctness.

**[require-member-order](/docs/rules/lint/classes/require-member-order)**

Orders the elements of classes/interfaces/traits/enums.

In the `coding-style` set. Safe fix.
