> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PHP Final Class

A `final` class in PHP is a class declaration prefixed with the `final` keyword, which explicitly prevents the class from being inherited or extended by any other class. When a class is marked as final, it terminates the inheritance chain, ensuring its internal implementation and state cannot be modified or overridden through subclassing.

```php theme={"dark"}
final class ClassName {
    // Properties and methods
}
```

## Engine Behavior and Inheritance

If a script attempts to define a class that inherits from a `final` class using the `extends` keyword, the PHP engine will halt execution and throw a `Fatal error` at compile time.

```php theme={"dark"}
final class ParentClass {
    public function execute(): void {}
}

// Fatal error: Class ChildClass may not inherit from final class (ParentClass)
class ChildClass extends ParentClass {
}
```

## Method Redundancy

Because a `final` class cannot be subclassed, it is impossible for any of its methods to be overridden. While PHP allows you to declare individual methods as `final` within a `final` class, doing so is logically redundant and has no additional effect on the engine's behavior.

## Instantiation and Composition

The `final` modifier strictly governs inheritance; it does not affect instantiation or composition. A `final` class retains standard object-oriented capabilities:

* It can be instantiated using the `new` keyword.
* It can inherit from another (non-final) class.
* It can implement one or more interfaces.
* It can import traits.

```php theme={"dark"}
class BaseEntity {}
interface CustomSerializable {}
trait Timestampable {}

// Valid: A final class extending a base class, implementing an interface, and using a trait
final class User extends BaseEntity implements CustomSerializable {
    use Timestampable;
    
    public string $username;
}

$user = new User(); // Valid instantiation
```

## Structural Restrictions

* **Abstract Modifier:** A class cannot be declared as both `abstract` and `final` simultaneously. These modifiers are mutually exclusive. Attempting to combine them (`abstract final class`) will result in a `Fatal error: Cannot use the final modifier on an abstract class`.
* **Interfaces and Traits:** The `final` keyword cannot be applied to `interface` or `trait` declarations. The PHP engine will throw a parse error, as the fundamental architecture of interfaces and traits requires them to be implemented or consumed by other structures.
* **Readonly Classes:** As of PHP 8.2, the `final` keyword can be combined with the `readonly` modifier (`final readonly class Name {}`).

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor PHP Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
