Skip to content

MIR0704

InvalidExtendClass

A class extends a class declared as final or annotated with @final in its docblock.

This issue was previously named FinalClassExtended (same code MIR0704).

<?php
final class Singleton {}
class MyClass extends Singleton {} // cannot extend final class

@final docblock annotations are also respected:

<?php
/** @final */
class Base {}
class Child extends Base {} // cannot extend @final class

A type that lists its subtypes with @phpstan-sealed (or @psalm-inheritors) rejects any other class, and an interface with @phpstan-require-extends rejects an implementing class that does not extend the named class:

<?php
/** @phpstan-sealed Circle */
interface Shape {}
final class Square implements Shape {} // not in the sealed list
class Model {}
/** @phpstan-require-extends Model */
interface HasTable {}
final class Report implements HasTable {} // must extend Model

Remove the final keyword (or @final annotation) from the parent class, or do not extend it. For a sealed type, add the class to its list; for @phpstan-require-extends, extend the required class.