---
title: "lint/classes/prefer-self-in-final"
pagination: false
---

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

<RuleId id="lint/classes/prefer-self-in-final" />

In the [`modernize`](/docs/rules/sets/modernize) and [`code-quality`](/docs/rules/sets/code-quality) sets. Safe fix.

## What it does

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

## Configuration

```toml title="pun.toml"
[lint.rules]
"classes/prefer-self-in-final" = "error"
```

To skip it in some files, add an [override](/docs/configuration/pun-toml#lint) or a [`@pun-ignore-file`](/docs/configuration/ignore-comments) comment.

## Replaces

- [`self_static_accessor`](https://cs.symfony.com/doc/rules/class_notation/self_static_accessor.html) (php-cs-fixer)
- [`ConvertStaticToSelf`](https://getrector.com/rule-detail/convert-static-to-self-rector) (rector)
- [`redundant-static`](https://mago.carthage.software/1.61.0/en/tools/linter/rules/#redundant-static) (mago-linter)

## Merged rules

These old IDs are now this rule. A config that still names one stops with an error. See [merged rules](/docs/migrate/merged-rules).

- `lint/classes/prefer-self-over-static`

Rector also rewrote `static::` to `self::` for private members of non-final classes; that case is not covered yet.

[More lint/classes rules](/docs/rules/lint/classes) · [Edit this page](https://github.com/shipfastlabs/pun/edit/main/crates/pun-config/rules/mapping.toml)
