PHP final Keyword

PHP finally Keyword
PHP extends Keyword

In this article, you will learn how to prevent a class to be inherited by another class in PHP. The final keyword in PHP is used to prevent a class from being inherited and to prevent the inherited method from being overridden.

examples of the FINAL keyword

Example 1. In this example, we prevent inheritance of a class using the final keyword.

<?php
final class MyClass {
  public $name = "John";
}

// This code will throw an error
class AnotherClass extends MyClass{};
?>
PHP finally Keyword
PHP extends Keyword

Stay up-to-date about PHP!

We don’t spam!

en English
X
Scroll to Top