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
webdevetc

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.



More...


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

Force trailing slash (redirect if no trailing slash exists) in .htaccess

How to convert between types in JS?

How to generate an array for a dropdown (with ['key' => 'value']) suitable for a dropdown, from a Laravel collection of Eloquent objects?

How to set up custom error pages in .htaccess for your Apache server (ErrorDocument)

How to see all of the options for an artisan command?

How to get the type of a variable in JS?

How to find out which php.ini file PHP is using?

How to set custom HTTP headers in Apache (by editing .htaccess)

Push vs Pop vs Shift vs Unshift

How to get the last character of a string in JS?