What does 'final class' and 'final function' (final method) mean in PHP?

PHP: What does 'final class' and 'final function' (final method) mean in PHP?

If a class is defined as final class then no other class can extend it. I.e. the following would result in an error:

  1.         final class DontExtendMe {}
  2.         class ThisCausesAnError extends DontExtendMe {}

A final method (final function ...) means that any subclasses of it's class cannot be overridden.

webdevetc profile pic

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This (webdevetc.com) is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.


Comments and discussion about What does 'final class' and 'final function' (final method) mean in PHP?

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the PHP language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

How to return JSON data to the user in Laravel?

How to show a specific view file for certain error codes?

How to check if a user is logged in, inside a blade file?

How to manually write your own pagination in PHP

What is the difference between var, let and const in Javascript?

How to exclude URLs from the Laravel CSRF protection?

How to change the order that migrations happen?

How to add the CSRF (Cross-site request forgery) token in Laravel?

PHP Date commonly used formats

What are macros in Laravel?